Skip to content Skip to sidebar Skip to footer

PHP Mailer Shows No Errors But Doesn't Send The Email

I'm creating a booking form as a favour but have decided to send mail via the domain, not the server. This is mainly for better security and less limits in responses and data trans

Solution 1:

You should look at your $mail->addAdress, $mail->addBCC and $mail->addReplyTo fields and follow the correct syntax for those fields.

Test the code below.

    <?php

    use PHPMailer\PHPMailer\PHPMailer;

    if(isset($_POST['submit'])) 
    {
        // Values need to be santiised

        $forename = $_POST['forename'];
        $surname = $_POST['surname'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $service = $_POST['service'];
        $date = $_POST['date'];
        $time = $_POST['time'];

        require '../vendor/autoload.php';

        $mail = new PHPMailer;
        $mail->isSMTP();
        $mail->SMTPDebug = 0;
        $mail->Host = 'smtp.hostinger.com';
        $mail->Port = 587;
        $mail->SMTPAuth = true;
        $mail->Username = 'test@handler.net';
        $mail->Password = '[PASSWORD]';

        $mail->setFrom('test@handler.net','Bookings'); // Emails sent via Noreply.

        $mail->addAddress('bookings@salon.com',''); // Email form responses sent to bookings@salon.com

        $mail->addReplyTo($email,$forename.' '.$surname); // Reply to the user who submitted the form.

        $mail->addBCC('outbox@handler.net',''); // Store record of all emails sent via the system.

        $mail->Subject = 'Booking Request'; // Subject of the email sent to admin@handler.net that the form responses will be contained within.

        $mail->isHTML(TRUE);
        $mail->Body = <<<EOD
            Booking request from {$forename} with email {$email}.<br  />
            Contact details: <br />
            Full name: {$forename} {$surname}<br />
            Email: {$email} <br />
            Phone number: {$phone} <br />
            Service: {$service} <br />
            Date: {$date} {$time}
EOD;
        if(!$mail->send()) { // Send the email.
          echo '';
          echo 'Mailer error: ' . $mail->ErrorInfo;
        } else {
          echo '';
        }
    }
    ?>

Solution 2:

This block of code is wrong, some quotes are missing

$mail->Body = '

    Booking request from '.$forename.' with email '.$email;'
    Test Values: $forename $surname $email $phone $service $date $time

To enable variable replacement on a string use double quotes, and you won't need to concatenate variables with dot(.), also this make possible to use escaped caracters like \n, try to adjust your code like this:

$mail->Body = "Booking request from $forename with email $email\n" .
              "Test Values: $forename $surname $email $phone $service $date $time";

Solution 3:

Firstly we have to view the error so therefore you have to set

$mail->SMTPDebug = 0;

into

$mail->SMTPDebug = 3;

So you can get that error to post against that error.


Post a Comment for "PHP Mailer Shows No Errors But Doesn't Send The Email"