Php电子邮件不发送

My code snippets are attached below.

I've managed to get this working on another page, so I simply copied and pasted that process and front end code and changed the variables to the new page and it's not working. My PHP logs don't indicate anything is undefined and it's not throwing any errors. I'm using phpmailer and the email auth is handled in another file which is confirmed to be working so the issue isn't there.

I think the issue lies in the process.php file.

Front end:

            <form class="contact" name="contact">
                <input type="hidden" name="to_email"  value="<?= $this->user->user_email; ?>" />

                <p>Enter your enquiry on the form below.</p> 
                <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Message</span>
                <textarea class="form-control" name="message" rows="5"></textarea>
                </div>
                <br><br>
                <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Phone Number</span>
                <input type="text" style="color: #333333" name="phone" class="form-control" placeholder="Optional" aria-describedby="basic-addon1"></input>
                <span class="input-group-addon" id="basic-addon1">Contact Name</span>
                <input type="text" style="color: #333333" name="from_name" class="form-control" aria-describedby="basic-addon1" value="<?= $this->user->user_contact_name; ?>"></input>
                </div>
                </form>

Front end script:

    $(document).ready(function () {
        $("input#submit").click(function(){
            $.ajax({
                type: "POST",
                url: "profile/process", // 
                data: $('form.contact').serialize(),
                success: function(msg){
                    alert("Your message has been sent, thanks!");   
                },
                error: function(){
                    alert("failure");
                }
            });
        });
    });
</script>

Process.php

<?php
$to = strip_tags($_POST['to_email']);
if (isset($_POST['name'])) {
$name = strip_tags($_POST['from_name']);
$email = 'example@example.com';
$message = strip_tags($_POST['message']);
$email_body = "You have received a new message. ".
" Here are the details:
 Name: $name 
 ".
"Email: $email
 Message 
 $message";
    $mail = new Mail;
    $mail_sent = $mail->sendMail(
        $to,
        $email,
        $name,
        Config::get('EMAIL_CONTACT_SUBJECT'),
        $email_body
    );
}?>

If you are using an external mail server:

  • Gmail: Your server might be flagged as "unusual activity", and thus the process of sending mail has been stuck at SMTP Error: Could not authenticate. This happened when, for example, you have registered your Gmail account at Malaysia, and however, you have tried to send a mail from United States. Check for errors with your authentication by debugging

     $mail->SMTPDebug = 3; 
    
  • Other mail service providers: If you're using other mail service provider, for example: cPanel web hosting, you might been blocked from using the server from sending unsolicited/mass mail, you can check the debug message (see above) to see what happen

If you are using a local mail server:

  • Most ISPs blocked the outgoing mail most of the time to combat with spam. Check the debug messages to see what happen.

Things did not look right:

<?php
$to = strip_tags($_POST['to_email']);
$name = isset($_POST['name'])?strip_tags($_POST['from_name']):"";
$email = 'example@example.com';
$message = strip_tags($_POST['message']);
$email_body = "You have received a new message. ".
        " Here are the details:
 Name: $name 
 ".
        "Email: $email
 Message 
 $message";
$mail = new Mail;
$mail_sent = $mail->sendMail(
        $to,
        $email,
        $name,
        Config::get('EMAIL_CONTACT_SUBJECT'),
        $email_body
);
?>