How to send an HTML email using SMTP in PHP(如何在 PHP 中使用 SMTP 发送 HTML 电子邮件)
问题描述
我已经能够在 PHP 中使用 SMTP 发送电子邮件,但是当我尝试将内容类型更改为 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 类上,但由于我们不知道您使用的是什么 Mail 类,所以很难回答.如果您还没有这样做,我真的会考虑使用 PHPMailer:https://github.com/PHPMailer/PHPMailer
The problem most likely lies in the Mail class, but since we don't know what Mail class you're using, it's difficult to answer. If you're not already doing so, I'd really think about using PHPMailer: https://github.com/PHPMailer/PHPMailer
这篇关于如何在 PHP 中使用 SMTP 发送 HTML 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PHP 中使用 SMTP 发送 HTML 电子邮件
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
