Send email using Gmail and PHP

This is really useful if you don’t have an email server.

Using your Gmail account for sending emails is great ;)

Steps:

  • Dowload the latest version of PHPmailer class
  • Include it in your script
  • Test with this code:
$mail  = new PHPMailer();
$mail->IsSMTP();
 
//GMAIL config
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "ssl";                 // sets the prefix to the server
	$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
	$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
	$mail->Username   = "gmailusername";  // GMAIL username
	$mail->Password   = "gmailpassword";            // GMAIL password
//End Gmail
 
$mail->From       = "from@email.com";
$mail->FromName   = "you name";
$mail->Subject    = "some subject";
$mail->MsgHTML("the message");
 
	//$mail->AddReplyTo("reply@email.com","reply name");//they answer here, optional
$mail->AddAddress("address@to.com","name to");
$mail->IsHTML(true); // send as HTML
 
if(!$mail->Send()) {//to see if we return a message or a value bolean
  echo "Mailer Error: " . $mail->ErrorInfo;
} else  echo "Message sent!";
Share and Enjoy:
  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • Google Bookmarks
  • BarraPunto
  • Bitacoras.com
  • FriendFeed
  • Meneame
  • Netvibes
  • Reddit
  • StumbleUpon
  • Tumblr
  • Wikio
  • RSS
  • email
  • PDF
  • Print

Related posts:

  1. How to Tweet from PHP and short Url with bit.ly
  2. Free SMS Notification for high server load
  3. Error reporting for PHP
  4. Prevent spam in your PHP site with akismet
  5. Page execution time PHP

Leave a Reply

Follow me