我已经能够使用PHP中的SMTP发送电子邮件,但是当我尝试将内容类型更改为HTML时,邮件无法发送。这是我尝试使用的代码:
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”参数,则可以成功发送消息。我不知道为什么添加它会引起问题。
.=
来连接电子邮件地址。 - Nisse Engström