[英]When i tried to send mail using phpmailer, i am getting error
Could not instantiate mail function.无法实例化邮件功能。
Message couldnot be sentMailer Error: Could not instantiate mail function.无法发送邮件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;
}
Have you tried with smtp ?
你试过smtp吗? The cause of
Could not instantiate mail function error may be more than one reason.
导致无法实例化邮件功能错误的原因可能不止一个。 when you try to send large emails and your PHP error log contains the message
Can not send a message: Too big then your mail transfer agent (Sendmail, postfix, Exim, etc) is refusing to deliver these emails.
当您尝试发送大型电子邮件并且您的 PHP 错误日志包含消息无法发送消息:太大时,您的邮件传输代理(Sendmail、postfix、Exim 等)拒绝发送这些电子邮件。
The solution is to configure the MTA to allow larger attachments.解决方案是配置 MTA 以允许更大的附件。 But this is not always possible.
但这并不总是可能的。 The alternate solution is to use SMTP.
另一种解决方案是使用 SMTP。 You will need access to a SMTP server (and login credentials if your SMTP server requires authentication), consider the given example.
您将需要访问 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';
Your Mistake: You used HOST as Localhost it's SMTP.mail.com change mail to your server您的错误:您使用 HOST 作为本地主机,它的 SMTP.mail.com 将邮件更改为您的服务器
You are using older version of PHPMailer also let me help you by typing the correct one您正在使用旧版本的 PHPMailer 也让我通过输入正确的来帮助您
You should download from PHPMailer GitHub Not vendor for this example您应该从 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.**
If your code looks good, try to install PostFix on your server.如果您的代码看起来不错,请尝试在您的服务器上安装 PostFix。
sudo apt-get install postfix
It worked for me on digital ocean.它在数字海洋上对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.