As I already posted earlier, PHP has several methods to send the mail. In this post I am going to cover the send mail using PHP Send mail.
Earlier I have posted about the send mail using SMTP with PHPMailer. Before this I have posted about the send mail using SMTP with core PHP.
For sending the mails using this method we need to set sendmail_path in php.ini.
Now let’s see how to send mail using SendMail using PHPMailer.
PHPMailer with SendMail
// Creating a Object of PHPMailer
$mail = new PHPMailer();
// By default this will use mail()
// Inform class to use the sendmail method
// Above line does the all trick
// Set the body
$body = file_get_content("body.html");
// Add Reply To
// Add From
// Add To Address
$address = "firstname.lastname@example.org";
$mail->AddAddress($address, "To Mail");
// Add the subject
$mail->Subject = "PHPMailer Test via Sendmail";
// Set the mail to be send as HTML
// Send the mail Finally
echo "Mailer Error: " . $mail->ErrorInfo;
echo "Message sent!";
Note: $mail->IsSendmail() is doing all the trick here.