HOW TO: Sending email using PHP (PHPMailer)
Posted by on 04 April 2018 10:11 AM

You can send email using PHPMailer from your PHP script with SMTP authentication. To use PHPMailer classes, you just need to download PHPMailer class files from the following URL:

Following is the sample code to send email from your PHP script with SMTP authentication:


$mail = new PHPMailer();

$mail->IsSMTP(); // send via SMTP
$mail->Host = ""; // SMTP servers
$mail->SMTPSecure = 'ssl'; // Enable SSL encryption, then change below port to 587. You may remove this line to use non-SSL with port 25 or 26 in below.
$mail->Port = "25"; //specify SMTP Port
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From     = "";
$mail->FromName = "Name";
$mail->AddReplyTo("","Your Name");

$mail->WordWrap = 50;                 // set word wrap
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the <b>HTML body</b>";
$mail->AltBody  =  "This is the text-only body";

   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;

echo "Message has been sent";


Please make sure that you make the changes in the above script as necessary. 

Note: For security reason, our mail servers require your script to pass SMTP authentication in order to send email.

(5 vote(s))
Not helpful

Comments (0)
Copyright © 1998 - 2018 Shinjiru International Inc. All Rights Reserved.