Send email from localhost (in windows os) with Gmail (SMTP) and PHPMailer
Friday, May 08, 2015
Process:
1) Download PHPMailer from google code or github
2) Extract to folder within you php project and rename it to phpmailer
3) Create gmail-sample.php and paste the code.
4) Send mail from browser (e.g. http://localhost/your-project/gmail-sample.php).
Code (gmail-sample.php):
1) Download PHPMailer from google code or github
2) Extract to folder within you php project and rename it to phpmailer
3) Create gmail-sample.php and paste the code.
4) Send mail from browser (e.g. http://localhost/your-project/gmail-sample.php).
Code (gmail-sample.php):
require("phpmailer/class.phpmailer.php");
$mailer = new PHPMailer();
/**** Email configuration***/
$mailer->Username = "your.username@gmail.com"; // your GMail username
$mailer->Password = "your-gmail-password"; // your GMail password
$mailer->AddAddress("example@domain.com"); // recipients email address
$mailer->FromName = "your name"; // readable name
$mailer->Subject = "Subject title";
$mailer->Body = "Here is the message you want to send to your friend.";
/***Email Host configuration***/
$mailer->Host = "ssl://smtp.gmail.com"; // GMail host
$mailer->Port = 465; //GMail SMTP port
$mailer->IsSMTP(); // use SMTP
$mailer->SMTPAuth = true; // turn on SMTP authentication
$mailer->From = $mail->Username;
/***Send Email***/
if(!$mailer ->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
Labels: PHP
Post a Comment