Quickest Way to Send Mails in Php Without Any External Libraries
If you are looking for sending simple, quick, functional emails with your PHP code, nothing is better than using the built-in mail()
function.
This is a no-nonsense stuff. Blazing fast too.
function sendEmail($email) {
$to = $email;
$subject = "Test Email";
$message='
<html>
<body>
<p>This is a test HTML email.</p>
</body>
</html>
';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$retval = mail($to,$subject,$message,$headers);
if( $retval == true ) {
error_log('mail sent');
error_log($to);
} else {
error_log(error_get_last()['message']);
error_log('mail NOT sent');
}
}
If you are getting no errors but your emails are not delivering, you would want to do the following:
1. Look for DKIM & SPF status of the sender email address domain under “Email Deliverability” in cPanel
.
2. and for Delivery status/logs under “Track Delivery” in cPanel
.
Note: If you looking for some fancy sunch as Attchments, SMTP and stuff and don’t mind external libraries then
you many want to read my this post: How to use PHPMailer Library for Sending Attachments With Emails.