Welcome Guest, Not a member yet? Register   Sign In
Email problem sending both a message AND an attachment at the same time
#1

[eluser]mademan[/eluser]
Ok, this seems like it should work, but I am not able to send an email using CI's native mail library to send an email with a message AND an attachment at the same time. I can see one or the other - the message OR the attachment, but not both at the same time.

Code:
// the email library is autoload
$this->email->to('[email protected]');
$this->email->from('[email protected]', 'My Name');
$this->email->subject('This is the subject');
$this->email->message('<p>This is an html message</p>');
$this->email->set_alt_message('This is a text message');
$this->email->attach('this/is/the/path/to/the/file.xls');
$this->email->send();

If I leave the code the way it is shown above only the attachment comes through fine, NOT the message.

If I only comment the message line, the attachment comes through just fine as expected.
If I only comment the attachment line, the message is sent to my email just fine as expected.

It's only when nothing is commented that I only see the attachment, not the message.


Any ideas?
#2

[eluser]mademan[/eluser]
Problem solved - I decided to use http://www.swiftmailer.org and it works perfect.
#3

[eluser]Tomasz OleÅ›[/eluser]
Here is my solution to this problem, the final code looks like this:

Code:
$config [ 'protocol' ] = 'sendmail';
$config [ 'mailpath' ] = '/usr/sbin/sendmail -t -i';
$config [ 'charset' ] = 'utf-8';
$config [ 'wordwrap' ] = TRUE;
$config [ 'mailtype' ] = 'html';
$config [ 'newline' ] = '\r\n';

$this->email->initialize( $config );
$this->email->clear( );
$this->email->to( 'email' );
$this->email->from( 'email' , 'name' );
$this->email->subject( 'subject' );
$this->email->message( '&lt;html&gt;&lt;head>&lt;/head&gt;&lt;body>' . $message . '&lt;/body&gt;&lt;/html>' );
$this->email->attach( $_SERVER [ 'DOCUMENT_ROOT' ] . '/upload/images/image.img' );    
$this->email->send( );

Hope it will help somebody in the future Smile
Greetings




Theme © iAndrew 2016 - Forum software by © MyBB