Jump to content

HTML Emails sent with PHP mail() are displayed in plain text?


gergy008

Recommended Posts

Ok, I am using the following code to send an email with PHP, And the email is in HTML. Yet PHP keeps sending it in plain text. How do I go about it?

 

Thanks in advance!!

 

	$topic="Some subject";
	$detail="<html><body><a href="">Some HTML email code</a></body></html>";
	$recipent=$_POST["email"]; //This is working, I have tested this already, It does send to the recipent.
	$headers="From: #####.co.uk <support@#####.co.uk>\n\r";
	$headers.="Content-Type: text/html";
	$sent=mail($recipent, $topic, $detail, $headers);

Link to comment
Share on other sites

use css to style the text but the css has to be in the message too

 

when using css in a message remember to escape all the quotes example color=\"#ff0000\" etc

 

Sorry, I must refine this a bit better.

 

Whatever code I try, The reciepent recieves plain text, In HTML form. The recipent actually sees the HTML tags.

 

Say I use this code:

<a href="http://www.google.co.uk/">Google</a>

in my email, That what the reciepent sees. Not Google or Google. Just <a href="http://www.google.co.uk/">Google</a>

 

Just added an example:

dzffno.jpg

Link to comment
Share on other sites

This is what i use

$to = "john@website.com";
$subject = "Subject";
$MsgHeader = "From: websitename <noreply@website.com> \n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "

<html>
<head>
<style type=\"text/css\">
table.logo{
width: 100%;
height: auto;
text-align: left;
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 0px; 
}
table.main{
width: 100%;
height: auto;
}
table.main td{
width: auto;
height: auto;
text-align: left;
font-size: 13px; 
font-family: tahoma, arial;
font-weight: normal;
color: #333;
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 15px; 
}
table.footer{
width: 100%;
height: auto;
}
table.footer td{
width: auto;
height: auto;
text-align: left;
font-size: 10px; 
font-family: tahoma, arial;
font-weight: normal;
color: #336699;
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 15px; 
}	
</style>
<title>HTML message</title>

</head>
<body>
<table class=\"logo\">
<tr><td><img src=\"http://www.website.com/pix/logo.png\"></td></tr>
</table>
<table class=\"main\">
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td>Dear John,</td></tr>
<tr><td> </td></tr>
<tr><td>Welcome</td></tr>
<tr><td> </td></tr>
<tr><td>Thank you for</td></tr>
<tr><td> </td></tr>
<tr><td>username: user</td></tr>
<tr><td>password: pass</td></tr>
<tr><td> </td></tr>
<tr><td>Text 2</td></tr>

<tr><td><a href=\"http://www.website.com\">website.com</a></td></tr>
<tr><td> </td></tr>
<tr><td>Regards</td></tr>
<tr><td> </td></tr>
<tr><td>Website Team</td></tr>
<tr><td> </td></tr>
<tr><td>Additional Message</td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
<table class=\"footer\">
<tr><td>Disclaimer </td></tr>
</table>
</body>
</html>";
mail($to, $subject, $MsgBody, $MsgHeader);

Link to comment
Share on other sites

This is what i use

$to = "john@website.com";
$subject = "Subject";
$MsgHeader = "From: websitename <noreply@website.com> \n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "

<html>
<head>
<style type=\"text/css\">
table.logo{
width: 100%;
height: auto;
text-align: left;
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 0px; 
}
table.main{
width: 100%;
height: auto;
}
table.main td{
width: auto;
height: auto;
text-align: left;
font-size: 13px; 
font-family: tahoma, arial;
font-weight: normal;
color: #333;
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 15px; 
}
table.footer{
width: 100%;
height: auto;
}
table.footer td{
width: auto;
height: auto;
text-align: left;
font-size: 10px; 
font-family: tahoma, arial;
font-weight: normal;
color: #336699;
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 15px; 
}	
</style>
<title>HTML message</title>

</head>
<body>
<table class=\"logo\">
<tr><td><img src=\"http://www.website.com/pix/logo.png\"></td></tr>
</table>
<table class=\"main\">
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td>Dear John,</td></tr>
<tr><td> </td></tr>
<tr><td>Welcome</td></tr>
<tr><td> </td></tr>
<tr><td>Thank you for</td></tr>
<tr><td> </td></tr>
<tr><td>username: user</td></tr>
<tr><td>password: pass</td></tr>
<tr><td> </td></tr>
<tr><td>Text 2</td></tr>

<tr><td><a href=\"http://www.website.com\">website.com</a></td></tr>
<tr><td> </td></tr>
<tr><td>Regards</td></tr>
<tr><td> </td></tr>
<tr><td>Website Team</td></tr>
<tr><td> </td></tr>
<tr><td>Additional Message</td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
<table class=\"footer\">
<tr><td>Disclaimer </td></tr>
</table>
</body>
</html>";
mail($to, $subject, $MsgBody, $MsgHeader);

 

In your headers, You used \n, Is it because I am using \r\n??

Link to comment
Share on other sites

i doubt it no char encoding or mime type

 

Well I am now using your headers and now I get the email in HTML... But nothing is in it...

 

Code:

 

$subject="Some subject";
	$detail="
<html>
<body bgcolor=\"#000000\" style=\"text-align:center\">
  <font color=\"#FFFFFF\" face=\"Myriad Pro, Century Gothic, Arial, serif\">Epic fail.</font>
</body>
</html>";
	$recipent=$_POST["email"];
	$headers = "From: #####.co.uk <support@#####.co.uk>\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1";
	$sent=mail($recipent, $subject, $detail, $headers);

Link to comment
Share on other sites

i just tried this as a test and got it fine

 

not sure if a font like Myriad Pro will work with email as I have never heard of it

 

<?php
$to = "email@website.com";
$subject = "Subject";
$MsgHeader = "From: websitename <webmaster@website.com> \n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "
<html>
<head>
<style type=\"text/css\">
.messagetext{ 
width: 100%; 
height: auto; 
text-align: left; 
color: #fff;
font-size: 13px;  
font-family: tahoma, arial;
background: #000; 
margin: 0px 0px 0px 0px;  
padding: 0px 0px 0px 0px; 
}
</style>
<title>HTML message</title>
</head>
<body>
<span class=\"messagetext\">Epic Fail</span>
</body>
</html>";
$send = mail($to, $subject, $MsgBody, $MsgHeader);

if ($send==true){
echo "sent";
}
else
{
echo "not sent";
}

?>

Link to comment
Share on other sites

or use it like this just to style the body

 

<?php
$to = "webmaster@website.com";
$subject = "Subject";
$MsgHeader = "From: websitename <webmaster@website.com> \n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "
<html>
<head>
<style type=\"text/css\">
body{ 
width: 100%; 
height: auto; 
text-align: center; 
color: #fff;
font-size: 13px;  
font-family: tahoma, arial;
background: #000; 
margin: 0px 0px 0px 0px;  
padding: 0px 0px 0px 0px; 
}
</style>
<title>HTML message</title>
</head>
<body>
Epic Fail
</body>
</html>";
$send = mail($to, $subject, $MsgBody, $MsgHeader);

if ($send==true){
echo "sent";
}
else
{
echo "not sent";
}

?>

Link to comment
Share on other sites

$headers="From: #####.co.uk <support@#####.co.uk>\n\r";

shouldn't you use below ?

$headers="From: #####.co.uk <support@#####.co.uk>\r\n";

 

Other errors I noted is this

$detail="<html><body><a href="">Some HTML email code</a></body></html>";

should be this

$detail="<html><body><a href=\"\">Some HTML email code</a></body></html>";

 

Link to comment
Share on other sites

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.