【问题标题】:When i tried to send mail using phpmailer, i am getting error当我尝试使用 phpmailer 发送邮件时,出现错误
【发布时间】:2020-06-02 02:57:33
【问题描述】:

无法实例化邮件功能。
无法发送邮件邮件程序错误:无法实例化邮件功能。

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;
}

【问题讨论】:

标签: php jquery node.js reactjs


【解决方案1】:

如果您的代码看起来不错,请尝试在您的服务器上安装 PostFix。

sudo apt-get install postfix

它在数字海洋上对我有用。

【讨论】:

    【解决方案2】:

    您尝试过 smtp 吗? Could not instantiate mail function错误的原因可能不止一个。当您尝试发送大型电子邮件并且您的 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';
    

    【讨论】:

    • 您的主机配置了吗?尝试使用 Gmail 一次。
    【解决方案3】:

    您的错误:您使用 HOST 作为 Localhost,它是 SMTP.mail.com 将邮件更改为您的服务器

    您使用的是旧版本的 PHPMailer,我也可以帮您输入正确的

    你应该从 PHPMailer 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.**
    

    【讨论】:

      猜你喜欢
      • 2018-02-27
      • 2021-05-11
      • 2014-03-22
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2012-08-23
      • 2011-04-05
      • 1970-01-01
      相关资源
      最近更新 更多