glln
glln

Reputation: 543

Gmail is ignoring my HTML emails

You've probably come across this error before. I cannot seem to fix it. Gmail seems to be ignoring my HTML emails and is just showing the code. All other clients (or all that I know of) are displaying the content correctly.

Here is my code (with certain things changed to hide the name)

     $to = "$EmailAddress";
     $subject = "My subject!";
     $headers = "From: [email protected]\r\n" .
     "X-Mailer: php";
     $headers .= "MIME-Version: 1.0\r\n";
     $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
     $message = '<html><body>';
     $message .= '<center><img width="300px" src="http://www.mydomain.co.uk/images/mylogo.png"/><br />';
     $message .= '<br /><br />';
     $message .= '<h2>Hello '.$UserName.',</h2>';
     $message .= '<b>Thanks for joining!</b><br /><br />';
     $message .= 'Please find your login details below.';
     $message .= '_____________________________________<br /><br />';
     $message .= 'Username: '.$UserName.'<br/>
                  Password: '.$Password.'<br />
                  <br />';
     $message .= '_____________________________________<br /><br />';
     $message .= 'Thanks,<br/>My company.<br/>';
     $message .= '<br/><a target="_new" href="http://www.mydomain.co.uk"/>www.mydomain.co.uk</a>';
     $message .= '</center>';
     $message .= 'my company &copy; 2012';
     $message .= '</html></body>';

     $success = mail($to,$subject,$headers,$message);

my Question is, is there a way to either offer an alternative plain text version of the email should the email client not be able to read this code or is there something I need to add in order for Gmail to understand it?

I apologise if this is a duplicate, but I cannot seem to find this question on here. Thanks in advance.

Upvotes: 3

Views: 4740

Answers (3)

Tei
Tei

Reputation: 1416

I don't think what you are trying here is standard. Emails are written in plain/text usually, not text/html. Theres a option to send emails as a mime-multipart message, but then you have a text/plain version for browsers withouth text/html support. You should be using a class to shield yourself from implementation details of mime.

Mi comment is for advanced PHP users. Begginers can do things manually, they don't have the experience of what things will break doing it that way. So the top voted comment here is enough for begginers. Professionales are better served using a class that create a correct mime type multipart file.

Upvotes: -1

Aventador
Aventador

Reputation: 217

Try using

Content-type: html;

I Have used it to solve a problem in my application.

Upvotes: -1

m-t
m-t

Reputation: 502

you have some typo's in your code, i don't know how other client displaying content correctly. i worked on them and got succeeded, hope will work for u too, try this;

$to = "$EmailAddress";
$subject = "My subject!";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = '<html><body>';
$message .= '<center><img width="300px" src="http://www.mydomain.co.uk/images/mylogo.png"/><br />';
$message .= '<br /><br />';
$message .= '<h2>Hello '.$UserName.',</h2>';
$message .= '<b>Thanks for joining!</b><br /><br />';
$message .= 'Please find your login details below.';
$message .= '_____________________________________<br /><br />';
$message .= 'Username: '.$UserName.'<br/>
Password: '.$Password.'<br />
<br />';
$message .= '_____________________________________<br /><br />';
$message .= 'Thanks,<br/>My company.<br/>';
$message .= '<br/><a target="_new" href="http://www.mydomain.co.uk"/>www.mydomain.co.uk</a>';
$message .= '</center>';
$message .= 'my company &copy; 2012';
$message .= '</body></html>';

$success = mail($to,$subject,$message,$headers);

This is what u looking for

Upvotes: 8

Related Questions