简体   繁体   中英

PHPMailer suddenly stops sending emails to non-local email addresses

So I am using PHPMailer to send reservation confirmation emails to users. 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. 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). 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. Still, I get NO email. BTW, I am using PHPMailer, specifically and only the two files mentioned in the includes in the script below

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)

You're sending to localhost, which means you're submitting to a local mail server. This should mean that you get identical results whether using isMail or isSMTP , which you are. It sounds like submission is working (your 250 OK results), but onward delivery from your mail server is not. This means there is nothing wrong with your PHPMailer code, but you need to check your mail server logs and config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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