Alexhoward Posted February 11, 2009 Share Posted February 11, 2009 Hi Guys, I'm having some issues with this as, to be honest, i don't get it..... what i'd like to do is send an HTML email to the customer, when the do certain things, but as some mail boxes don't like HTML emails i realised that i'd also have to send a text version.. rather than having a tick box or something to choose, i've read that you can send them both at once using a multipart form... however, i can't get it to work... here's what i have so far: <?php // multiple recipients $to = 'me@mymail.com' . ', '; // note the comma $to .= 'someone@theirmail.com'; $boundary = "nextPart"; $headers = "Content-Type: multipart/alternative; boundary = $boundary\r\n"; // subject $subject = 'Testing an HTML/Text email'; //Text Version $headers .= "\n--$boundary\n"; // beginning \n added to separate previous content $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; //$headers .= "Text only..., will it work...?"; $message = 'Text only..., will it work...?' ; //HTML Version // To send HTML mail, the Content-type header must be set $headers .= "\n--$boundary--\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Me <me@mymail.com>, Someone Else <someone@theirmail.com>' . "\r\n"; $headers .= 'From: Add Some Music <no-reply@addsomemusic.co.uk>' . "\r\n"; // message $message = ' <html> <head> <title>Test an HTML email</title> </head> <body> <p><img src="http://www.addsomemusic.co.uk/images/ASM_Logo.jpg" width="150"></p> <p>Some Text.....</p> </body> </html> '; // Mail it $mail_sent = mail($to, $subject, $message, $headers); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> could anyone please tell me what i'm doing wrong...? Thanks in advance! Add Some Music http://www.addsomemusic.co.uk Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 11, 2009 Share Posted February 11, 2009 save yourself the time and use PHPMailer: http://phpmailer.codeworxtech.com here is an example...it's more complicated then what you are doing, but it has the HTML/Text stuff you want: http://phpmailer.codeworxtech.com/index.php?pg=examples Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted February 11, 2009 Author Share Posted February 11, 2009 Thanks for the reply rhodesa, however this is just me testing... Everything is already setup, sending text emails from the site, with mail forms and all that, I just want to alter the code to send HTML, but of course, I also need to send Text Any pointers would be much apprecaited Thanks! Add Some Music http://www.addsomemusic.co.uk Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 11, 2009 Share Posted February 11, 2009 at first glance, you have a couple problems...the multipart/alternative header is good, but text/plain and text/html headers should actually be in $message. Also, when you add the HTML message part, you replace the value of $message instead of appending to it. here is an example i found you may want to look at: http://us2.php.net/manual/en/function.mail.php#85772 Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted February 11, 2009 Author Share Posted February 11, 2009 Thanks for your help... This is gonna take some looking in to..... i'll report back when i got my head round it a bit better... cheers, oh, quick question. If you send a text and an html email at the same time, how does the receivers email choose which to display....? or is that a silly question... Thanks Again Add Some music http://www.addsomemusic.co.uk Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 11, 2009 Share Posted February 11, 2009 it should choose HTML if it is supported, and fall back on Text if it doesn't Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.