How to send E-mail using PHP - Software Testing

Empowering Technology

Post Top Ad

Responsive Ads Here

May 15, 2019

How to send E-mail using PHP

Use Below code to send a Mailer using PHP:

 // use PHP Mailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/Autoload.php';

$body="Enter Mail Body here";

// send email with create html body data
$mail = new PHPMailer(true);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host       = "ssl://"; // SMTP server
$mail->SMTPDebug  = 1; // enables SMTP debug information (for testing) 1 = errors and messages 2 = messages only
$mail->SMTPAuth   = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "ENTER HOSTNAME HERE";      // sets GMAIL as the SMTP server
$mail->Port       = 465;       // set the SMTP port for the GMAIL server
$mail->Username   = "ENTER USERNAME HERE";  // GMAIL username
$mail->Password   = "ENTER PASSWORD HERE";         // GMAIL password
$mail->Subject    = "ENTER SUBJECT HERE";
// add email addresses
$mail->AddAddress('ENTER TO HERE', 'NAME');
$mail->AddCC('ENTER CC HERE', 'NAME');
$mail->addAttachment('ATTACHMENT NAME.csv');
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (!$mail->Send()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
} else {
   echo "Message sent!";

No comments:

Post a Comment

Thanks a lot for your valuable Comment!

Post Bottom Ad

Responsive Ads Here