3 回答
TA贡献1836条经验 获得超13个赞
你试过用smtp吗?无法实例化邮件功能错误的原因可能有多个原因。当您尝试发送大型电子邮件并且PHP错误日志包含消息无法发送消息时:太大,那么您的邮件传输代理(Sendmail,postfix,Exim等)拒绝传递这些电子邮件。
解决方案是将 MTA 配置为允许更大的附件。但这并不总是可能的。另一种解决方案是使用 SMTP。您将需要访问 SMTP 服务器(如果您的 SMTP 服务器需要身份验证,则需要登录凭据),请考虑给定的示例。
$mail->IsSMTP();
$mail->Host = "smtp.example.com";
// used only when SMTP requires authentication
$mail->SMTPAuth = true;
$mail->Username = 'smtp_username';
$mail->Password = 'smtp_password';
TA贡献1890条经验 获得超9个赞
您的错误:您使用主机作为本地主机,SMTP.mail.com 更改邮件到您的服务器
您正在使用旧版本的PHPMailer也让我通过键入正确的一个来帮助您
对于此示例,您应该从 PHP 梅勒 GitHub 非供应商处下载
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; //for Gmail
$mail->SMTPAuth = true;
$mail->Username = 'user@gmail.com';
$mail->Password = 'your Gmail pass';
$mail->Port = 587; // TCP port
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}```
**Your error was that you used HOST as localhost and older version of PHPMailer.
But use default mail() but change the PHP version to 7.3 since it's better now.**
- 3 回答
- 0 关注
- 201 浏览
添加回答
举报
