Phpmailer Not Sending and Not Giving Error

Why phpmailer is not sending mail to my domain mail server

PHPMailer doesn't throw exceptions by default – you have to ask for them by passing true to the constructor, as in $mail = new PHPMailer(true);. Without that you have to check the return values from methods like send() to find out if they worked.

Errors are stored in the ErrorInfo property – see any of the code examples provided with PHPMailer to see how to handle errors correctly.

You can also set $mail->SMTPDebug = 2; to see what your mail server is saying. Beyond that, read the PHPMailer troubleshooting guide.

PHP Mailer shows no errors but doesn't send the email

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 '';
}
}
?>

PHPMailer does not give error message?

Your function sendMail doesn't return a boolean. Since it's an array / object the result is always true in this case. Try printing $response before your if statement and you will see the error.



Related Topics



Leave a reply



Submit