The PHPMailer documentation in various examples of using the examples assumes that in the final part of the code - send - an error message should appear if it fails:
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
What I would prefer to do in the event of a failure is to return to the built-in PHP mail () function. The advantage is that the email will still be sent to me, and it may carry a PHPMailer failure notification.
if (!mail->send()) {
$to = 'me@mydomain.com';
$subject = 'You have a new e-mail subscriber + ERROR REPORT';
$message = 'user input data and error description here';
mail($to, $subject, $message);
} else {
$mail->Subject = 'You have a new e-mail subscriber';
$mail->Body = $message;
$mail->send();
}
I hesitate to use the PHPMailer language as an expression IF
, since a complete shutdown to PHP seems more secure and reliable for me. Is there a better way to write this?
: . PHPMailer mail()
. . SMTP (, smtp.google.com), . , - , . , .