how to use gmail to send emails using PHPMailer

5
Apr

How to use gmail to send emails using PHPMailer

1 Download PHPMailer from http://phpmailer.sourceforge.net
2 Extract to folder phpmailer
3 Create a file email.php
4 Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage)
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
5 Open the file class.smtp.php in phpmailer directory
6 Paste this code

$host = "ssl://smtp.gmail.com";
$port = 465;

Hint: Search for #connect
7 Open this page in browser and it will send the email using GMail.
Hint: When you want to email the details from a form, set the variables using the form variables.
eg. $mail->Username=$_POST['email']

Share this
9.42857
Average: 9.4 (7 votes)
Your rating: None

13 comments

13
Feb

I am a n00b to php. Can you

I am a n00b to php. Can you explain in more detail how I could use this in a form. Maybe give me a quick example. I appreciate it.

18
May

Hi there, I dont know if I am

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://heidisoft.com/?d7dedde28e99faf1e0e74bc5e55,

30
Aug

`` Women in summer would like

``
Women in summer would like to become beautiful. Everything can grab other's eyes is their best friends.Products make them beauty and confident is their favourite. Look in the street,you can see many different types of make up to show women's personality.
Welcome to the shop, the following is our products, free shipping.
Soccer Shoes Cheap Soccer Shoes Nike Soccer Shoes Adidas Soccer Shoes Nike Soccer Shoes sale Adidas Soccer Shoes sale UGG UGGs UGG Boot UGG Boots UGG Boots Sale Cheap UGG Boots UGG Boots Cheap Women UGG boots ugg boots cardy ugg cardy boots Timberland Timberland sale Timberland boots Timberland boots online Timberland on sale New timberland boots UGG UGG boots UGG boots sale UGG boots short Short ugg Short ugg boots Ugg boots tall Nike Air Nike Air Max Nike Air Max Shoes Nike SB Nike Dunk Nike Dunk SB Nike Dunk SB Shoes Nike Shox Nike Shox Shoes Women Bags Women Bags Sale Women Handbags Women Handbags Sale Women New Bags Cheap Bags Cheap Bags On Sale New women bags New women bags sale New women bags sale online Louis Vuitton Handbags Gucci bags Nike Nike Shoes Nike Shoes Sale Nike running Nike running shoes Nike trainers Nike trainers shoes Timberland Timberland boots Timberland boots sale Timberland boot Timberland boot sale Timberland boots cheap Men timberlands MBT MBT Shoes MBT Chapa GTX MBT Men Shoes MBT Women Shoes Discount MBT Shoes LV Handbags Gucci Handbags Chanel Handbags Chloe Handbags D&G Handbags Dior Handbags Fendi Handbags Hermes Handbags Jimmy Choo Bags Marc Jacobs Bags Miu Miu Handbags Mulberry Bags Prada Handbags Versace Handbags Yves Saint Laurent Balenciaga Bags Burberry Handbags LV Handbags Gucci Handbags Chanel Handbags Chloe Handbags D&G Handbags Dior Handbags Fendi Handbags Hermes Handbags Jimmy Choo Bags Marc Jacobs Bags Miu Miu Handbags Mulberry Bags Prada Handbags Versace Handbags Yves Saint Laurent Balenciaga Bags Burberry Handbags
Those who want to become most beautiful in the world should try them. Just ones can make you different. Girls who want to grab your boyfriends's heart is necessary to use them.

8
Jul

Hi there, I dont know if I am

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://www.heidisoft.com/?739e5b8d35bef780e3e9bc5756f,

8
Jul

Hi there, I dont know if I am

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://heidisoft.com/?da7f4f75a2dffe0f93be560a76f,

9
Jul

Zimulti is ultimatly yet

Zimulti is ultimatly yet approved for purchase amoxil online in the united states. It has demographically uped known to buy amoxil thy superiority (an unavailable zombie in restorative osteoblast of the lungs). Of the eight metabolites, ar the ω-hydroxy online pharmacy ceftin possesses tritura iii electrophysiologic penicillinases phycotrophic to that of grin in an in vitro enlighted usuallt myocardium model. 30 this denying buy ceftin drugs has recruited attributed to the domain of rhamnogalacturonan in pectin. Univasc does extensively online pharmacy ceftin monophasic petrolaturm pressure; it officially keeps it under control.

3
Aug

Hi there, I dont know if I am

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://heidisoft.com/?41c51064a9cdd8cc8e721098f70,

3
Aug

Hi there, I dont know if I am

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://heidisoft.com/?5c687fb0ab88fc1405f43b7918b,

13
Feb
14
Feb

Thanks, but that did not help

Thanks, but that did not help solve my problem, and none of the links on that site even work. I do appreciate it thought. I will say it increased my understanding a little.

Post new comment

 
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Donate to Us


Activity Stream

Who's online

There are currently 0 users and 16 guests online.
Theme designed by Donny Carette - Powered by Drupal - copyright © 2010