我想知道为什么Phpmailer偶尔无法发送电子邮件

我想知道为什么Phpmailer偶尔无法发送电子邮件,php,email,phpmailer,Php,Email,Phpmailer,所以我有这个函数: $toAddress = $sendTo; try { $mail = new PHPMailer(); // create a new object $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only $mail->SMTPAuth = true; // a

所以我有这个函数:

$toAddress = $sendTo;
try {
    $mail = new PHPMailer(); // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->Host = self::$host;
    $mail->Port = 587;//self::$port; // or 587
    $mail->SMTPSecure = 'tls';
    $mail->IsHTML(true);
    $mail->CharSet = self::$charset;
    $mail->Username = self::$username;
    $mail->Password = self::$password;
    $mail->SetFrom(self::$from, self::$fromAlias);
    $mail->Subject = trim("Here's your csv.");
    $mail->Body = trim("Thank you for using List Master Application. Please download your csv on this link. <a href='http://36.55.238.182:81/pagination/download?file=".$fileName."'>Here!</a>");
    if(is_array($toAddress))
    {
        foreach($toAddress as $to_line)
        {
            $mail->AddAddress($to_line);
        }
    }
    else
    {
        $mail->AddAddress($toAddress);
    }

    if ($mail->send())
    {
          log_message('debug', 'sucessfully send email to ' . $sendTo);
          return TRUE;
    }
    else
    {
         log_message('debug', 'Failed to send email to ' . $sendTo);
         log_message('debug', 'Failed message is : ' . $mail->ErrorInfo);
         return FALSE;
    }

    } catch (phpmailerException $e) {
          log_message('debug', $e->errorMessage()); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
          log_message('debug', $e->getMessage()); //Boring error messages from anything else!
    }
当电子邮件无法发送时,为什么会显示此信息


这意味着什么?

PHPMailer是一个从PHP网页向另一个网页发送邮件的简单系统,它是一个代码库。通过PHP或PHP代码从web服务器安全、轻松地发送电子邮件是一个非常简单的系统

<?php
    $subject ="Send Mail";
    $receive_email = "Example@gmail.com";
    $full_name=$_POST['full_name'];
    $phone=$_POST['phone'];
    $email=$_POST['email'];
    $address=$_POST['address'];
    $user_details="Full Name: ". $full_name. "\n Phone No: ". $phone."\n Address: ".$address;

    require_once("class.phpmailer.php");
    $mail = new PHPMailer();

    $body = "</pre>
    <div>";
    $body .= "<p>Full Name :".$full_name."</p>";
    $body .= "<p>Phone :".$phone."</p>";
    $body .= "<p>Address :".$address."</p>";
    $body .= "</div>" ;

    // And the absolute required configurations for sending HTML with attachement

    $mail->AddAddress("Example@gmail.com", "My Website Name");
    $mail->Subject = "Send Mail";
    $mail->MsgHTML($body);

    if(!$mail->Send()) {
        echo "There was an error sending the message";
        exit;
    }
    echo "Thank you for contacting us!";
?>


正如上次您询问时我所说的,这一点已经涵盖在内。解决这个问题的最好方法不是直接发送,而是安装一个本地邮件服务器并通过它进行中继。邮件服务器是专门为处理断断续续的连接而设计的,它也是目前为止处理在应用程序中提交页面期间发送电子邮件的最快方式。指南和PHPMailer wiki中的其他文章也介绍了这一点。此外,您的代码仍然基于一个过时的示例(即使是5.2),并且因为您没有启用异常(通过将
true
传递给构造函数),你的try/catch将一事无成。@Synchro有我可以为你发送邮件的最新代码建立的链接吗?这真的不是火箭科学,你知道:
<?php
    $subject ="Send Mail";
    $receive_email = "Example@gmail.com";
    $full_name=$_POST['full_name'];
    $phone=$_POST['phone'];
    $email=$_POST['email'];
    $address=$_POST['address'];
    $user_details="Full Name: ". $full_name. "\n Phone No: ". $phone."\n Address: ".$address;

    require_once("class.phpmailer.php");
    $mail = new PHPMailer();

    $body = "</pre>
    <div>";
    $body .= "<p>Full Name :".$full_name."</p>";
    $body .= "<p>Phone :".$phone."</p>";
    $body .= "<p>Address :".$address."</p>";
    $body .= "</div>" ;

    // And the absolute required configurations for sending HTML with attachement

    $mail->AddAddress("Example@gmail.com", "My Website Name");
    $mail->Subject = "Send Mail";
    $mail->MsgHTML($body);

    if(!$mail->Send()) {
        echo "There was an error sending the message";
        exit;
    }
    echo "Thank you for contacting us!";
?>