Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Sending HTML email using PHP [header problems]
3stripe
✭✭
Hi folks,
I'm having problems generating an html email... something's not right in the code below but I can't figure out what... when I receive the email in gmail it's all wrong.
Any ideas as usual on fixing my php idiocy are much appreciated
Cheers!
James
I'm having problems generating an html email... something's not right in the code below but I can't figure out what... when I receive the email in gmail it's all wrong.
Any ideas as usual on fixing my php idiocy are much appreciated
Cheers!
James
//Get email address of a friend, and sends them an html email
// Get the email address from flash
$Email1 = $HTTP_POST_VARS['email1'] ;
// Email starts here
$ToEmail = $Email1;
$ToName = $Email1;
$Yourname = "Bob Smith";
$Youremail = "email@email.com";
$ToSubject = "EMAIL SUBJECT HERE";
$html_content = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<h1>Test email only</h1>
<p>Blah blah blah</p>
</body>
</html>';
// To send HTML mail, the Content-type header must be set
$Headers = 'MIME-Version: 1.0' . "\r\n";
$Headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$Headers .= 'From: '.$Yourname.' <".$Youremail.">' . "\r\n";
$Message = $html_content;
// Send email
mail($ToName." <".$ToEmail.">",$ToSubject, $Message, $Headers);
echo "status=ok";
?>
0
This discussion has been closed.
Comments
Well actually, now that I read over that section again, it seems only to apply to Windows servers, so if you know you're running a *nix server than you shouldn't need to worry about it. However, if not, then I'd assume you'd want to use just the mail address.
One problem left - something in the from email address is not right - it's appearing in the email like this:
From: Joe Bloggs <".$Youremail."@z1lnx007.web.vi.net>
So somethings not quite right here... can't work out where it is picking up the host domain from either!
$Headers .= 'From: '.$Yourname.' <".$Youremail.">' . "\r\n";
Perhaps either use
$Headers .= "From: $Yourname <$YourEmail>\r\n";
or
$Headers .= 'From: '.$Yourname.'<'.$Youremail.'>'."\r\n";
(i think)
The second one worked (I've switched to just "\n"s for now)
Cheers folks. Now onto the fun part of prettifying the html...
Not sure about this one - having just tested on my pipex webmail, I don't see anything at all in this email which isn't good!
But yeah i'm definitely hitting that night time barrier.
some example code that i just picked up off the net:
$boundary = "nextPart"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: Me <sales@mysite.com>\r\n"; $headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n"; //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 .= "This is the plain version"; //html version $headers .= "\n--$boundary\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "This is the <b>HTML</b> version"; mail("me@mymail@mac.com", "An HTML Message", "", $headers);