Sending emails using PHPMailer v5.0.0 and GMail
Requirements:
1 : PHPMailer v5.0.0 and above
2 : GMail account
Download the PHPMailer v5.0.0 and above from http://sourceforge.net/project/showfiles.php?group_id=26031&package_id=252700
Now create a file you can call mail.php on your system and open it with your favorite text editor.
Paste below code into it and save.
<?php
date_default_timezone_set(‘Asia/Calcutta’); // to set default timezone
require_once(‘../class.phpmailer.php’);
// optional, gets called from within class.phpmailer.php if not already loaded
//include(“class.smtp.php”);
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
// enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->SetFrom(‘name@yourdomain.com’, ‘First Last’);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
// optional, comment out and test
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,This is the HTML BODY "; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$address = "towhom@towhomdomain.com";
$mail->AddAddress($address, "First Last");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}else {
echo "Message sent!";
}
?>
For any ssl exceptions/ errors:
change fgets() to @fgets() to surpass the ssl error
———————–
At class.smtp.php
before line 104 (before #connect), use this lines:
$host = “ssl://smtp.gmail.com”;
$port = 465;
———————–
In the PHP.ini, you need to have this option:
extension=php_openssl.dl
Additional Resources:
http://phpmailer.worxware.com/index.php?pg=examples
http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html
Windows environments, this seems to work:
544-configuring-php-under-windows-use-gmail-external-smtp-server-ssl
Share or Bookmark This Post With :
- mtop – MySQL terminal based query monitor
- Kohana – Swift, Secure, and Small PHP 5 Fram...
- FormMail – free form processing PHP script
- Xataface – The fastest way to build a front-...
- dotProject – the Open Source Project Managem...
- The jQuery Form Plugin
- DocVerse has officially been acquired by Google
- HDGraph – a free tool for Windows to draw mu...
- RandomClass jQuery Plugin
- Paparazzi – a small utility for Mac OS X to ...
- Send emails using PHPMailer an...
- Firefox Addons Essential for S...
- Free SEO Tools From SEOMoz.org...
- URL Rewriting for PHP Web Appl...
- Multiple Instances of Tomcat w...
- Apache 2.x + Tomcat 4.x + Load...
- Pagination in JSP/Java
- PHP – Mysql Open Source ...
- java.lang.OutOfMemoryError: Ja...
- HOW TO Subversion+Apache on Fe...




