[英]When i tried to send mail using phpmailer, i am getting error
無法實例化郵件功能。
無法發送郵件Mailer 錯誤:無法實例化郵件功能。
require 'PHPMailer/PHPMailerAutoload.php';
$mail =new PHPMailer;
$mail->HOST ='localhost';
$mail->PORT = 25;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = 'Username';
$mail->Password = 'Pass';
$mail->setFrom('info@zoeticpolymers.com');
$mail->addAddress('nitesh54546@gmail.com','Nitesh');
$mail->AddReplyTo("info@zoeticpolymers.com");
$mail->isHTMl(true);
$mail->Subject = 'PHP Mailer Subject';
$mail->Body = '<h1>You are Welcome Here.....</h1>';
if(!$mail->send()){
echo 'Message couldnot be sent';
echo 'Mailer Error: ' . $mail->ErrorInfo; die;
}else{
echo 'Message has been sent'; die;
}
你試過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';
您的錯誤:您使用 HOST 作為本地主機,它的 SMTP.mail.com 將郵件更改為您的服務器
您正在使用舊版本的 PHPMailer 也讓我通過輸入正確的來幫助您
您應該從 PHPMailer GitHub Not vendor 下載此示例
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.**
如果您的代碼看起來不錯,請嘗試在您的服務器上安裝 PostFix。
sudo apt-get install postfix
它在數字海洋上對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.