Gmail is ignoring my HTML emails

扶醉桌前 提交于 2019-12-10 11:27:31

问题


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: no-reply@mydomain.co.uk\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.


回答1:


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


回答2:


Try using

Content-type: html;

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




回答3:


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.



来源:https://stackoverflow.com/questions/9908791/gmail-is-ignoring-my-html-emails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!