Send Email using PHP

Download PHPMailer from https://github.com/PHPMailer/PHPMailer.git

 

$ git clone https://github.com/PHPMailer/PHPMailer.git

 

<?php

require_once(“PHPMailer/PHPMailerAutoload.php”);

$mail = new PHPMailer(); // create a new object

$mail->IsSMTP(); // enable SMTP

$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only

$mail->SMTPAuth = true; // authentication enabled

$mail->SMTPSecure = ‘ssl’; // secure transfer enabled REQUIRED for Gmail

$mail->Host = “smtp.gmail.com”;

$mail->Port = 465; // or 587

$mail->IsHTML(true);

$mail->Username = “username@gmail.com”;

$mail->Password = “password”;

$mail->SetFrom(“username@gmail.com”);

$mail->Subject = “Test”;

$mail->Body = “hello”;

$mail->AddAddress(“username@gmail.com”);

if(!$mail->Send()) {

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

} else {

echo “Message has been sent”;

}

?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s