Jump to content

I have had this problem before but it fixed itself...


gergy008

Recommended Posts

I'm having trouble with this emailing script. As you can see it clearly sets the contect typw to text/html but when you read the email it's not in HTML like intended :(

 

        $to=$email;
$subject='Activate your account.';
$message="
<html>
<head>
  <title>Activate your account that doesn't show in HTML damn it -.-</title>
</head>
<body>
  <p>Nothing here.</p>
</body>
</html>
";
// To send HTML mail, the Content-type header must be PROPERLY set
$headers  = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
// Additional headers
$headers .= 'To: $fname <$email>' . '\r\n';
$headers .= 'From: **************' . '\r\n';
$headers .= 'Reply-To: ******************' . '\r\n';
$headers .= 'X-Mailer: PHP/' . phpversion();	
// Mail it
$mail=mail($to, $subject, $message, $headers);

 

Can someone help me solve why it's sending as plain text and not HTML this is getting annoying :(

 

Thanks in advance,

i don't like messing with all those details of mime types, etc. i suggest that you use an existing email class to make things simpler. i use rmail. if you follow the example scripts included in the download, it is very easy to set HTML, add attachments, etc.

 

http://www.phpguru.org/downloads/Rmail/Rmail%20for%20PHP/

 

I understand that your question relates to HTML and not attachments, but rmail does a great job of making HTML emails simple whether you add attachments or not.

The reason the OPs code doesn't work is probably that the EOL characters are enclosed in single quotes, not double quotes. This is causing the email headers to be invalid.

 

Do this instead:

<?php
        $to=$email;
$subject='Activate your account.';
$message="
<html>
<head>
  <title>Activate your account that doesn't show in HTML damn it -.-</title>
</head>
<body>
  <p>Nothing here.</p>
</body>
</html>
";
// To send HTML mail, the Content-type header must be PROPERLY set
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
// Additional headers
$headers .= "To: $fname <$email>\r\n";
$headers .= "From: **************\r\n";
$headers .= "Reply-To: ******************\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();	
// Mail it
$mail=mail($to, $subject, $message, $headers);
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.