Sending email using PHP (PHPMailer)

Last modified: February 24, 2020
You are here:
Estimated reading time: 1 min

With SMTP authentication, you can send email via PHP. You just have to download PHPMailer class files to use the PHPMailer courses:

The following is the sample code for SMTP authentication to send e-mails using the PHP script:

$mail->Host = “mail.domain.com”; // 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 = “email@domain.com”; // SMTP username
$mail->Password = “password”; // SMTP password

$mail->From     = “email@domain.com”;
$mail->FromName = “Name”;
$mail->AddAddress(“Recipient@emailaddress.com”,”Name”);
$mail->AddReplyTo(“yourname@domain.com”,”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 HTML body“;
$mail->AltBody  =  “This is the text-only body”;

if(!$mail->Send())
{
echo “Message was not sent

“;
echo “Mailer Error: ” . $mail->ErrorInfo;
exit;
}

echo “Message has been sent”;

?>

Please ensure that you make needed modifications to the above script.

Note: Our mail servers require your SMTP authentication script to submit email for safety reasons.

Was this article helpful?
Dislike 0
Views: 45
Customer Services Contact

Need Help? Send a Ticket to our 24X7 Technical Support Team

Subtitle
Subscribe Newsletter

Subscribe to Casbay Newsletter for online tips, events and latest promotion !

Copyright © 2010 – 2020 Casbay Sdn. Bhd. (1042688-D). All Rights Reserved.

All Trademarks Are The Property of Their Respective Owner.