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
include("class.phpmailer.php");
// Creating a Object of PHPMailer
$mail = new PHPMailer();
// By default this will use mail()
// Inform class to use the sendmail method
$mail->IsSendmail();
// Above line does the all trick
// Set the body
$body = file_get_content("body.html");
// Add Reply To
$mail->AddReplyTo("replyto@yourdomain.com","Reply To");
// Add From
$mail->SetFrom("from@yourdomain.com", "From");
// Add To Address
$address = "to@otherdomain.com";
$mail->AddAddress($address, "To Mail");
// Add the subject
$mail->Subject = "PHPMailer Test via Sendmail";
// Set the mail to be send as HTML
$mail->MsgHTML($body);
// Send the mail Finally
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
?>
Note: $mail->IsSendmail() is doing all the trick here.