简体   繁体   English

PHPMailer突然停止向非本地电子邮件地址发送电子邮件

[英]PHPMailer suddenly stops sending emails to non-local email addresses

So I am using PHPMailer to send reservation confirmation emails to users. 因此,我正在使用PHPMailer向用户发送预订确认电子邮件。 It has worked for months but all of the sudden, it just stopped working. 它已经工作了几个月,但是突然之间,它就停止了工作。 Nothing changed (at least I didn't change anything). 什么都没改变(至少我什么都没改变)。 The PHPMailer files are still intact and I didn't play with the DNS/MX records. PHPMailer文件仍然完整,我没有处理DNS / MX记录。 Here is the script for sending emails. 这是发送电子邮件的脚本。 It sends one to the user and one to me at my local email address. 它通过我的本地电子邮件地址向用户发送一个,向我发送一个。 The email directed to me sends successfully but the client doesn't receive it. 发送给我的电子邮件已成功发送,但客户端未收到。 When I try sending it to the client only, the debugging info says that the email has sent. 当我尝试仅将其发送给客户端时,调试信息显示电子邮件已发送。 It keeps saying 250 OK when referring to the recipient address (which I guess means its accepted). 当提及收件人地址时(我认为这表示接受),它总是说250 OK It also shows the message in its whole and then, in the end, it closes the connection. 它还显示了整个消息,然后最后关闭了连接。 In the script, it should also echo "true" and it does that. 在脚本中,它还应echo "true" ,并执行此操作。 Still, I get NO email. 不过,我没有收到电子邮件。 BTW, I am using PHPMailer, specifically and only the two files mentioned in the includes in the script below 顺便说一句,我正在使用PHPMailer,特别是下面脚本中的include中提到的两个文件

Here is the script for the actual sending of the email. 这是实际发送电子邮件的脚本。

<?php
include "connection.php";
session_start();
if(isset($_POST['problem_name'])){

    $name = $_POST['name'];
    $address = $_POST['address'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $model_name = $_POST['model_name'];
    $problem_name = $_POST['problem_name'];
    $package_name = $_POST['package_name'];
    $price = $_POST['price'];

    $query = "INSERT INTO ext_orders (`date`, `name`, `address`, `phone`, `email`, `product`, `problem`, `package`, `addons`, `price`) VALUES ('".date("Y/m/d")."', '".$name."', '".$address."', '".$phone."', '".$email."', '".$model_name."', '".$problem_name."', '".$package_name."', 'No', ".intval($price).")";

    if(mysqli_query($link, $query)){

        $latest_id = mysqli_insert_id($link);

        /***** COMPOSING OF EMAIL TO CUSTOMER AND A BCC TO MOBILECARE ******/
        $message=
        '
        <h1>Mobilecare Urgent Repair Order Confirmation</h1> <br />

        <h3> Personal Details </h3><br/>

        <b>Name:</b>    '.$name.'<br />
        <b>Urgent Repair Address:</b> '.$address.'<br />
        <b>Email:</b>   '.$email.'<br />
        <b>Phone Number:</b> '.$phone.'<br />

        <h3> Product and order details </h3><br/>

        <b>Model:</b> '.$model_name.'<br/>
        <b>Type of Repair:</b> '.$problem_name.'<br/>
        <b>Price:</b> '.$price.'<br/><br/>

        If there are any problems with the information above, please reply to this email!<br/><br/>

        Thank you,<br/>
        Mobilecare.

        ';

        include "../phpmailer/class.smtp.php";
        include "../phpmailer/class.phpmailer.php";

        $mail = new PHPMailer();
        //Tell PHPMailer to use SMTP
        $mail->isSMTP();
        $mail->SMTPDebug = true;
        //Enable SMTP debugging
        // 0 = off (for production use)
        // 1 = client messages
        // 2 = client and server messages
        $mail->Host = localhost;
        //Set who the message is to be sent from
        $mail->setFrom('info@coherenthub.com', 'Mobilecare'); // info@mobilecare.ae
        //Set an alternative reply-to address
        //$mail->addReplyTo('replyto@example.com', 'First Last');
        //Set who the message is to be sent to
        $mail->addAddress(''.$email.'', ''.$name.'');
           // $mail->AddBCC("info@coherenthub.com", "Mobilecare");  // info@mobilecare.ae
        //Set the subject line
        $mail->Subject = 'Mobilecare Order Confirmation';
        //Read an HTML message body from an external file, convert referenced images to embedded,
        //convert HTML into a basic plain-text alternative body
        $mail->MsgHTML($message); 
        //Replace the plain text body with one created manually
        $mail->AltBody = 'This is a plain-text message body';

        if ($mail->send()) {

            echo "true";

        }

    }
    else{
        echo "fail";
    }


}

?>

All answers and comments would be appreciated. 所有的答案和评论将不胜感激。

I have tried: - Commenting out $mail->isSMTP() - Playing with the MX Records (reverted all changes, though) - Redownloading PHPMailer (latest version) 尝试: -注释掉$mail->isSMTP() -与MX记录播放(恢复所有变化,虽然) -重新下载PHPMailer的(最新版)

You're sending to localhost, which means you're submitting to a local mail server. 您正在发送到localhost,这意味着您正在提交到本地邮件服务器。 This should mean that you get identical results whether using isMail or isSMTP , which you are. 这意味着无论使用isMail还是isSMTP ,您都将获得相同的结果。 It sounds like submission is working (your 250 OK results), but onward delivery from your mail server is not. 听起来提交工作正常(您的250 OK结果),但是从邮件服务器继续发送则无效。 This means there is nothing wrong with your PHPMailer code, but you need to check your mail server logs and config. 这意味着您的PHPMailer代码没有任何问题,但是您需要检查邮件服务器日志和配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM