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
PHP Warning: PHP Startup: Unable to Load Dynamic Library 'Pdo_Mysql.So'
Strip HTML Tags and Its Contents
Rewrite All Queries to Not Need the .PHP Extension Using a Mod_Rewrite Rewriterule
PHP Float Calculation 2 Decimal Point
I Want a Pagination to My Options Page of Wordpress Plugin
Codeigniter Redirect -- the Uri You Submitted Has Disallowed Characters
Jquery UI Saving Sortable List
Foreach with Three Variables Add
PHP Array, Are Array Indexes Case Sensitive
How to Send Email with PDF Attachment Using PHP
Hide Added to Cart Message in Woocommerce
Status Detail: 3045:The Currency Field Is Missing
Using PHP Include to Separate Site Content
Download Multiple Files in One Http Request
Do I Have to Use MySQL_Real_Escape_String If I Bind Parameters
Convert Unicode to HTML Entities Hex
Set User Permissions | Artisan Command Will Not Run in Code But Works Fine on Command Line