I stumbled on something similar using XAMP and was able to send emails through PHPMailer PHP library.
There is a variety of examples that can be found in PHPMailer/examples/
that can be quite helpful. Below is a sample code that can be used to send an email using PHPMailer.
Note: it requires downloading the library files and adjusting the path
to the require
or use
files which are Exception, PHPMailer, and
SMTP.
Also, This implementation requires the sender's username and password to send the email not efficient for contact forms.
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
$mail = new PHPMailer(true);
$mail->CharSet = "utf-8";
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
$mail->Username = "Email to Send From"; // GMAIL username
$mail->Password = "#########"; // GMAIL password
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = "465"; // set the SMTP port for the GMAIL server
$mail->From= $emailFrom;
$mail->FromName='SenderName';
$mail->AddAddress($emailTo, $name);
$mail->Subject = 'EMAIL SUBJECT';
$mail->IsHTML(true);
$mail->Body = "
Dear ".$name.", <br><br>
Some Text/Message Content. <br><br>
Regards";
// Temporary fix, remove if SSL available
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
try {
$mail->Send();
// Sent Successfully
}catch (Exception $e) {
echo "Mail Error - >".$mail->ErrorInfo;
}
Hope this helps :)