Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/78654-solved-html-mail-problem/
Share on other sites

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>";

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");

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";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.