• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTML e-mail with attachment problem


when trying to send html e-mail, everything is 100% fine.

As soon as i add an attachment, the html portion of the e-mail does not display at all, but it is there ( when i use "Show Original" with gmail ).

I comment the attachment out, and it's fine. The attachment comes thru fine though when it is left in.

Anything i'm missing? I appreciate the help.

This is not being called in any sort of loop.

$this -> load -> library('email');
        $this -> load -> library('mailtemplate');


        $this -> email -> from('[email protected]','T');
        $this -> email -> to($To);
        $this -> email -> reply_to('[email protected]', 'T');

        $Subject = 'blah';
        $this -> email -> subject($Subject);

        $Body = 'My message body with not too much -stuff-';

        $Message = $this -> mailtemplate -> get_header().$Body.
                    $this -> mailtemplate -> get_footer(true);

        $this -> email -> message($Message);
        $this -> email -> attach($Attachment);

        $this -> email -> send();

what about other web email services and clients? how do they treat the email?

advise testing yahoo, hotmail, etc... as well as desktop clients like outlook, thunderbird, and mail.app

HTML email is pretty tricky to get right across all services. and if you throw in attachments... well, even more complicated.

also, each service is constantly changing their code base so today might be the first day of some new random buggy feature they rolled out.

i looked at the CI Email.php library and it looks like it should be handling your situation properly (aka to email RFC standards), but trying out a spectrum of other services will give some better idea if it is CI's problem or an individual service kink.

[quote author="sophistry" date="1204748680"]what about other web email services and clients? how do they treat the email?

advise testing yahoo, hotmail, etc... as well as desktop clients like outlook, thunderbird, ...[/quote]

I tested with Yahoo & Hotmail. It's the same exact issue with Yahoo but, with hotmail it displays the html rather than rendering it.

But the same happens with the phpmailer(sourceforge) so i'm thinking it might be the mail server (hmail) and something i've not configured properly?

Come to think of it, this is the first time i'm attempting to send an e-mail with an attachment via hmail. I'll spend some time on their forums as well and see what i come across.

And will try another mailserver as well.

Maybe this will allow someone to help me better; below is the debug output from the CI mail class. I've attempted to construct a *very* basic message with an attachment and still no go:

I replaced my domain name with {mydomain}

Debug:Your message has been successfully sent using the following protocol: mail

User-Agent: CodeIgniter
Date: Wed, 5 Mar 2008 10:19:56 -0500
From: "{mydomain}"
Reply-To: "{mydomain}"
X-Sender: [email protected]{mydomain}.com
X-Mailer: {mydomain}
X-Priority: 3 (Normal)
Message-ID: <{id}@{mydomain}.com>
Mime-Version: 1.0

Content-Type: multipart/mixed; boundary="B_ATC_47ceba1cebeda"
This is a multi-part message in MIME format.
Your email application may not support this format.

Content-Type: multipart/alternative; boundary="B_ALT_47ceba1cebed4"

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

This is a test!

Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
This is a test
&lt;html&gt;&lt;body&gt;<span style=3D"color:#FF0000;">This is a test!</span>&lt;/body&gt;</h=


Content-type: application/x-unknown-content-type; name="ABC.csv"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64



I've even tried 'full' html for the html body.

title - /title



please return with a debug matrix of where your email sending breaks down so you can isolate the problem.

tests (for each service):
send plaintext alone
send html alone
send attachment "alone"
send text and html
send text and attachment
send html and attachment
send all three

RFC 2046 makes for edifying reading see esp section 5.1.3 and 5.1.4 for multipart standards. those section detail the difference between alternative and mixed multiparts - there may be something in changing the default mixed to default to alternative.

finally, it looks like you didn't paste all of the email because there is no closing boundary on the base64 encoded attachment. according to the CI Email.php library code a closing boundary is added.

similar problem - html email arrives as html code. not a server issue cause phpmailer works fine. any xss filtering is off ... any idea what could cause this?

@stef25 - please realize you won't get anywhere with help debugging email unless you post exactly which service and/or client and code that you are using.

[quote author="stef25" date="1204755787"]similar problem - html email arrives as html code. not a server issue cause phpmailer works fine. any xss filtering is off ... any idea what could cause this?[/quote]

If phpmailer works fine, then maybe for CI, you've gotta state that you're sending html e-mail.

Either with $config in email.php in the config folder or with $email -> initialize($config)?

Have you tried either?

Sure ... i just thought there would be a simple answer, like something to do with filtering for security. here is my entire controller. please ignore the success / fail messages at the bottom, thats another issue.

the mail arrives fine with all the from / to emails and names filled in properly. only issue is that the body of the email is <p>all your base are belong to us</p>. this is the case both in Outlook and Gmail. Mail is sent via our linux dev machine on which phpmailer had no problem sending out html email.

All this code is very straightforward ... im stumped!

class Mailer extends Controller {
    function index() {
        //load the default view, the main index.php html design

        //check to see if form is being submitted
            //load email library
            //text alternative
            $textMail = "this is a text replacement";
            //grab values
            $fromName = $this->input->post('fromName');
            $fromEmail = $this->input->post('fromEmail');
            $toName = $this->input->post('toName');
            $toEmail = $this->input->post('toEmail');                    
            //insert values
            $this->email->from($fromEmail, $fromName);
            $this->email->to($toEmail, $toName);
            $this->email->subject($fromName.' would like to recommend Company X to you');
            $this->email->message('<p>All your base are belong to us</p>');
            echo $this->email->print_debugger();
            //send mail + success / fail message            
            if (!$this->email->send()) {
                $feedback = array(
                'message' => 'Sorry, message could not be sent'
            else {
                $feedback = array(
                'message' => 'Message sent!'

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.