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';
 }

Leave a comment