Skip to content

Instantly share code, notes, and snippets.

@mahedi2014
Created September 13, 2015 10:17
Show Gist options
  • Select an option

  • Save mahedi2014/3e6bdc15ead44a000715 to your computer and use it in GitHub Desktop.

Select an option

Save mahedi2014/3e6bdc15ead44a000715 to your computer and use it in GitHub Desktop.
Send mail with phpmailer and gmail smtp
<?php
//add to composer.json "phpmailer/phpmailer": "~5.2"
require_once 'vendor/autoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->SMTPSecure = 'tls'; // or 'ssl'
$mail->Port = 587; //465 for ssl
$mail->Username = "[email protected]";
$mail->Password = ""; //your gmail password
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email one-by-one to multiple users in .
$mail->From = "[email protected]";
$mail->FromName = "Your Name";
$mail->addAddress("[email protected]","User 1");
$mail->addAddress("[email protected]","User 2");
$mail->addCC("[email protected]","User 3");
$mail->addBCC("[email protected]","User 4");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment