Php 同一电子邮件中的HTML和纯文本

Php 同一电子邮件中的HTML和纯文本,php,email,html-email,Php,Email,Html Email,我正在构建一个基于PHP的新闻稿应用程序。我知道在html旁边发送纯文本版本的电子邮件也是一种很好的做法。我的问题是如何在实践中做到这一点?只是简单地把一个放在另一个下面?比如: <p style="font-weight:bold;">This is a newsletter!</p> <p style="color:red;"> You can read awesome things here! <br/> <a hre

我正在构建一个基于PHP的新闻稿应用程序。我知道在html旁边发送纯文本版本的电子邮件也是一种很好的做法。我的问题是如何在实践中做到这一点?只是简单地把一个放在另一个下面?比如:

<p style="font-weight:bold;">This is a newsletter!</p>
<p style="color:red;">
   You can read awesome things here!
   <br/>
   <a href="www.the-awesome-site.com">check out us on the web!</a>
</p>

This is a newsletter\r\n
You can read awesome things here!\r\n
check out us on the web: www.the-awesome-site.com

这两个不会互相干扰吗?我的意思是,如果mailer客户端能够理解HTML,那么在邮件末尾,内容几乎相同的纯文本将令人困惑。或者,如果客户端无法解析html,那么用户将在友好的纯文本之前看到令人烦恼的原始html源代码。有没有办法根据情况来隐藏无用的东西?如果PHPMailer很重要,我将使用它。

PHPMailer是一个很好的类,因为它可以检测电子邮件客户端何时不支持HTML

Check out this code snippet. It should help a little.

require("PHPMailer-master/PHPMailerAutoload.php");

$mail = new PHPMailer();
$mail->IsSMTP();

$mail->Host = "mail.somemailserver.com";  
$mail->SMTPAuth = false;


$mail->From = $someemail;
$mail->FromName = "Who ever";
$mail->AddAddress($email);
$mail->AddCC($anotheremail);

$mail->WordWrap = 50;



$mail->IsHTML(true);

$mail->Subject = "Some subject";

$mail->Body    = "<html>Content goes here</html>";


//if the client doesn't support html email use
$mail->AltBody = "Content";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

通过使用$mail->AltBody,您可以发送纯文本电子邮件。希望这有帮助

PHPMailer是一个很好的类,因为它可以检测电子邮件客户端何时不支持HTML

Check out this code snippet. It should help a little.

require("PHPMailer-master/PHPMailerAutoload.php");

$mail = new PHPMailer();
$mail->IsSMTP();

$mail->Host = "mail.somemailserver.com";  
$mail->SMTPAuth = false;


$mail->From = $someemail;
$mail->FromName = "Who ever";
$mail->AddAddress($email);
$mail->AddCC($anotheremail);

$mail->WordWrap = 50;



$mail->IsHTML(true);

$mail->Subject = "Some subject";

$mail->Body    = "<html>Content goes here</html>";


//if the client doesn't support html email use
$mail->AltBody = "Content";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

通过使用$mail->AltBody,您可以发送纯文本电子邮件。希望这有帮助

好的,我用的是同一个,我用的是同一个