sKunKbad Posted November 24, 2007 Share Posted November 24, 2007 I've looked at a few tutorials on sending HTML email. All the tags show up in the email, and none of the HTML formatting is being applied. $email = "stinkbomb@yourhouse.com"; $content = "<p style='color:blue'This text should be blue</p>"; $header = "From: My Store <info@mystore.com>\r\n"; $header .= "Reply-To: info@mystore.com\r\n"; $header .= "Return-Path: info@mystore.com\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail ("$email","Look at my HTML email","$content","$header"); What am I doing wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/ Share on other sites More sharing options...
Stooney Posted November 24, 2007 Share Posted November 24, 2007 make sure what ever email client your using has viewing emails as html enabled. Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-397996 Share on other sites More sharing options...
Sulman Posted November 24, 2007 Share Posted November 24, 2007 Are you getting anything at all displayed? If not it could be that you haven't closed you p tag correctly: $content = "<p style='color:blue'This text should be blue</p>"; should be: $content = "<p style=\"color:blue\">This text should be blue</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398039 Share on other sites More sharing options...
PFMaBiSmAd Posted November 24, 2007 Share Posted November 24, 2007 Proper document tags would help as well - <html> <head> ... </head> <body> ... </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398135 Share on other sites More sharing options...
Wes1890 Posted November 24, 2007 Share Posted November 24, 2007 Try: $email = "stinkbomb@yourhouse.com"; $content = "<html><head></head><body><p style='color:blue'>This text should be blue</p></body></html>"; $header = "From: My Store <info@mystore.com>\r\n"; $header .= "Reply-To: info@mystore.com\r\n"; $header .= "Return-Path: info@mystore.com\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail ("$email","Look at my HTML email","$content","$header"); ------------ You can also space it like so: ------------ $email = "stinkbomb@yourhouse.com"; $content = " <html> <head></head> <body> <p style='color:blue'>This text should be blue</p> </body> </html> "; $header = "From: My Store <info@mystore.com>\r\n"; $header .= "Reply-To: info@mystore.com\r\n"; $header .= "Return-Path: info@mystore.com\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail ("$email","Look at my HTML email","$content","$header"); Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398178 Share on other sites More sharing options...
sKunKbad Posted November 24, 2007 Author Share Posted November 24, 2007 OK, I guess I just need to use a email client that shows HTML. So I have to do it multipart. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398212 Share on other sites More sharing options...
cooldude832 Posted November 24, 2007 Share Posted November 24, 2007 also try puting the mail tag in an "if" statement <?php if(mail()){ echo "It went"; } else{ echo "It didn't"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398222 Share on other sites More sharing options...
sKunKbad Posted November 24, 2007 Author Share Posted November 24, 2007 This is what I am currently using, and it works: <?php $to = 'whatever72@yahoo.com'; $subject = 'Test HTML email'; //create a boundary string. It must be unique - so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: Brian Evaslim <brian@evaslim.com>\r\nReply-To: brian@evaslim.com\r\nReturn-Path: brian@evaslim.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. $message = " --PHP-alt-$random_hash Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-$random_hash Content-Type: text/html; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-$random_hash-- "; $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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398233 Share on other sites More sharing options...
cooldude832 Posted November 24, 2007 Share Posted November 24, 2007 don't supress the errror on the mail function, if it will error fix it, don't ignore it Quote Link to comment https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/#findComment-398234 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.