PHPMailer with PHP Send Mail

  • Avinash
  • 3
  • Sep 05, 2011
  • Web Development

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

IsSendmail(); // Above line does the all trick // Set the body $body = file_get_content("body.html"); // Add Reply To $mail->AddReplyTo("[email protected]","Reply To"); // Add From $mail->SetFrom("[email protected]", "From"); // Add To Address $address = "[email protected]"; $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!"; } ?>
<?php
 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("[email protected]","Reply To");

 // Add From
 $mail->SetFrom("[email protected]", "From");

 // Add To Address
 $address = "[email protected]";
 $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.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • http://cis.com sunil

    please provide me phpmail as soon as possible.
    thanks

  • KM Srinivas

    Hi Avinash, I’m getting an error on my wordpress website like “Could not execute: /usr/sbin/sendmail”.
    My plan is Ultimate and all sub domain websites also geting the same error. I am using wordpress for all mu sub domains. can you tell me any solution.