Welcome Guest, Not a member yet? Register   Sign In
HTML e-mail with attachment problem
#1

[eluser]rweston[/eluser]
Hello,

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.

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

        $this->email->clear(true);

        $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();
#2

[eluser]sophistry[/eluser]
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.
#3

[eluser]rweston[/eluser]
[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.
#4

[eluser]rweston[/eluser]
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}

Code:
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}"
Return-Path:
Reply-To: "{mydomain}"
X-Sender: DoNotReply@{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.

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

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

This is a test!


--B_ALT_47ceba1cebed4
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=
tml>

--B_ALT_47ceba1cebed4--

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

TGFzdCBOYW1lLEZpcnN0IE5hbWUsTWVtYmVyIFR5cGUsVXNlcm5hbWUsUGFzc3dvcmQNCiwsLCwN
ClBhcnJpc2gsTmFuY3ksVGVhY2hlcixOLlBhcnJpc2gsbnA3NTkzNTg3Mg0KTWFyb29uLEVkd2Fy
ZCxUZWFjaGVyLEUuTWFyb29uLGVtMjAyMjAyNjgNCkNvbmxvbixQZXRlcixUZWFjaGVyLFAuQ29u
...............
..............
.............
............
...........
..........
NzEyDQpOdmV0c2t5LEp1bGlvLEFkbWluaXN0cmF0b3IsSi5OdmV0c2t5LGpuOTk3NTU4NTkNCg==

--B_ATC_47ceba1cebeda--
#5

[eluser]rweston[/eluser]
I've even tried 'full' html for the html body.

html
head
title - /title
/head
body

message

/body
/html
#6

[eluser]sophistry[/eluser]
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

also,
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.
#7

[eluser]stef25[/eluser]
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?
#8

[eluser]sophistry[/eluser]
@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.
#9

[eluser]rweston[/eluser]
[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?
#10

[eluser]stef25[/eluser]
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!


Code:
class Mailer extends Controller {
    function index() {
                
        //load the default view, the main index.php html design
        $this->load->view('index');    

        
                
        //check to see if form is being submitted
        if($this->input->post('sendCheck'))
        {
            //load email library
            $this->load->library('email');
            
            //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>');
            $this->email->set_alt_message($textMail);
            echo $this->email->print_debugger();
                        
            //send mail + success / fail message            
            if (!$this->email->send()) {
                $feedback = array(
                'message' => 'Sorry, message could not be sent'
                );    
                $this->load->vars($feedback);
            }            
            else {
                $feedback = array(
                'message' => 'Message sent!'
                );    
                $this->load->vars($feedback);
            }                              
        }                
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB