3 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊
你試過用smtp嗎?無法實(shí)例化郵件功能錯(cuò)誤的原因可能有多個(gè)原因。當(dāng)您嘗試發(fā)送大型電子郵件并且PHP錯(cuò)誤日志包含消息無法發(fā)送消息時(shí):太大,那么您的郵件傳輸代理(Sendmail,postfix,Exim等)拒絕傳遞這些電子郵件。
解決方案是將 MTA 配置為允許更大的附件。但這并不總是可能的。另一種解決方案是使用 SMTP。您將需要訪問 SMTP 服務(wù)器(如果您的 SMTP 服務(wù)器需要身份驗(yàn)證,則需要登錄憑據(jù)),請(qǐng)考慮給定的示例。
$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貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
您的錯(cuò)誤:您使用主機(jī)作為本地主機(jī),SMTP.mail.com 更改郵件到您的服務(wù)器
您正在使用舊版本的PHPMailer也讓我通過鍵入正確的一個(gè)來幫助您
對(duì)于此示例,您應(yīng)該從 PHP 梅勒 GitHub 非供應(yīng)商處下載
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.**

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果您的代碼看起來不錯(cuò),請(qǐng)嘗試在服務(wù)器上安裝 PostFix。
sudo apt-get install postfix
它在數(shù)字海洋上為我工作。
- 3 回答
- 0 關(guān)注
- 94 瀏覽
添加回答
舉報(bào)