Created
September 13, 2015 10:17
-
-
Save mahedi2014/3e6bdc15ead44a000715 to your computer and use it in GitHub Desktop.
Send mail with phpmailer and gmail smtp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = "mahedi2014@gmail.com"; | |
$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 = "mahedi2014@gmail.com"; | |
$mail->FromName = "Your Name"; | |
$mail->addAddress("mahedi201422@gmail.com","User 1"); | |
$mail->addAddress("mahedi2014222@gmail.com","User 2"); | |
$mail->addCC("mahedi20141@gmail.com","User 3"); | |
$mail->addBCC("mahedi20142@gmail.com","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