How to use PhpMailer with SMTP authentication?
You can easily send mail through php with SMTP authentication using PhpMailer by following the step given below.
Step 1: First download the PHPMailer script using below direct link.
PHPMailer.zip
Step 2: Download and unzip the php mailer file under public_html folder.
Step 3: Once after extracting the file, your path will be public_html/PHPMailer.
Step 4: Use this PHPMailer script to send mail in your webpage.
Your PHP code will be as we shown below.
require_once
("/home/username/public_html/PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Host = "yourdomain.com"; // SMTP server
$mail->Username = "sending@yourdomain.com";
// SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->From = "sending@yourdomain.com";
$mail->FromName = "Test";
$mail->AddAddress("receive@yourdomain.com");
// Receiving Mail ID, it can be either domain mail id (or ) any
other mail id i.e., gmail id
$mail->Subject ="PhpMailer script with basic smtp
authentication";
$mail->AltBody = " ";
$mail->WordWrap = 80;
$body = "test message";
$mail->MsgHTML($body);
$mail->IsHTML(true);
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message Sent!";
}
Note: If you are extracting the PHPMailer_5.2.4 under any name, then your path will be /home/username/public_html/anyname/class.phpmailer.php. The user name you have provided here is your cpanel user name.