Send Email Using PHPMailer and GMail

Here is the script :

include "phpMailer2/class.phpmailer.php";
 $mailer = new PHPMailer();
 $mailer->IsSMTP();
 $mailer->Host = 'ssl://smtp.gmail.com';
 $mailer->Port = 465;
 $mailer->SMTPAuth = TRUE;
 $mailer->Username = 'sample@gmail.com';  // Change this to your gmail adress
 $mailer->Password = 'samplexxx';  // Change this to your gmail password
 $mailer->From = 'sample@gmail.com';  // This HAVE TO be your gmail adress
 $mailer->FromName = 'Your Website'; // This is the from name in the email, you can put anything you like here
 $mailer->IsHTML( true );
 $mailer->Subject = 'Your Website: ' . $subject;
 $mailer->Body = 'Name: 
‘ . $name . ‘
';
 $mailer->Body .= 'Email: 
‘ . $email . ‘
';
 $mailer->Body .= 'Message: 
‘ . $message . ‘
';
 $mailer->AddAddress( myfriendsemail@yahoo.com );  // This is where you put the email address of the person you want to mail
 if(!$mailer->Send())
 {
echo "
“;
echo ”

Message was not sent

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

";
 }
 else
 {
echo "
“;
echo “Your message has been sent.”;
echo “
";
  $action = 'something';
 }
Advertisements

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

%d bloggers like this: