如何在PHP中使用SMTP发送HTML电子邮件 [英] How to send an HTML email using SMTP in PHP
问题描述
我已经能够使用PHP在PHP中发送电子邮件,但是当我尝试将内容类型更改为HTML时,电子邮件不会被传递。这是我试图使用的代码:
I've been able to send an email using SMTP in PHP, but when I try to change the Content Type to HTML, the email doesn't get delivered. This is the code I'm trying to use:
require_once "Mail.php";
$from = "FPM <forms@fpmofames.com>";
$from_name = "FPM";
$host = "localhost";
$username = "username";
$password = "password";
$subject = "Subject";
$message = "Message";
$to = "<example@example.com>";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'MIME-Version' => '1.0',
'Content-Type' => "text/html; charset=ISO-8859-1"
);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $message);
如果我从标题中拿出Content-Type参数,它会发送消息。我不知道为什么添加会导致问题。
If I take the 'Content-Type' argument out of the headers, it sends the message just fine. I don't know why adding that causes a problem.
推荐答案
问题最有可能在于Mail类,但是由于我们不知道什么邮件类你;重用,它很难回答。如果你还没有这样做,我真的会考虑使用PHPMailer http://phpmailer.worxware.com/
The problem most likely lies in the Mail class, but since we dont know what Mail class you;re using, its difficult to answer. If you;re not already doing so, I'd really think about using PHPMailer http://phpmailer.worxware.com/
这篇关于如何在PHP中使用SMTP发送HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!