How to send emails out using PHPMailer and GMail

I’ve been working on a schedule calendar project that can be iframed into any kind of website. This schedule will be a real-time calendar which can be used for class registration, training classes, webinar registration, cooking schools, camping registration, and more …. The calendar will be run on Linux server and MySQL Database.

Step 1: download class phpmailer on sourceforge.net

Step 2: unzip the package and place all files in a folder called /includes/ anywhere on your server. However, you need to access to this folder from a php page though.

Step 3: go to google page to find out how to configure the settings for SMTP outgoing mail server. You can read the settings here https://mail.google.com/support/bin/answer.py?answer=75291

Step 4: create a php file called email_out.php (for example) and save it outside the /includes/ folder.

Step 5: include once the phpmailer class in this file and create a new PHPMailer object in order to send email out.

You can view my sample codes below.

<?php
require_once(“includes/classes/class.phpmailer.php”);

$mailer = new PHPMailer(); //create an object
$mailer->IsSMTP();
$mailer->IsHTML(true); // if you send text message, comment this line
$mailer->Host = ‘ssl://smtp.gmail.com:465’;
$mailer->SMTPAuth = TRUE;
$mailer->Username = ‘your_email@gmail.com’;  // Change this to your Gmail address
$mailer->Password = ‘your_gmail_password’;  // Change this to your Gmail password
$mailer->From = ‘your_email@gmail.com’;  // This HAVE TO be your Gmail address
$mailer->FromName = ‘anything here’; // This is the from name in the email, you can put anything you like here
$mailer->Body = ‘<table border=”1″><tr><td>This is the main body of the email</td></tr></table>’;
$mailer->Subject = ‘This is the subject of the email’;
$mailer->AddAddress(‘yourfriend_email@yahoo.com’);  // This is where you put the email address of the person you want to send this email

if(!$mailer->Send())
{
echo “Message was not sent successfully<br/ >”;
echo “Mailer Error: ” . $mailer->ErrorInfo;
}
else
{
echo “Message has been sent successfully”;
}
exit(); //remember to exit, so you won’t leave any trail here
?>