Sunday, October 5, 2014

Install PHPMailer 5.2.4 and use smtp gmail



1) PHPMailer download
https://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list
I download PHPMailer_5.2.4.zip and use winrar to unzip and put it in
C:\xampp\htdocs\phpmailertest

2)Configuration php.ini to enable openssl
In C:\xampp\php\php.ini
extension=php_openssl.dll
 If not, you may get the following message:
"SMTP -> ERROR: Failed to connect to server:
 Unable to find the socket transport "ssl" -
 did you forget to enable it when you configured PHP? (1909703479) "

3) Restart Apache

4) Create index.php under  C:\xampp\htdocs\phpmailertest. The red code below is import for using gmail as SMTP.  Change jiansentest and mypassword to your gmail account and password.
<?php
error_reporting(E_ALL);
require("PHPMailer_5.2.4/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug  = 2;
$mail->From = "jiansentest@gmail.com";
$mail->FromName = "Jiansen";
$mail->Host = "smtp.gmail.com"; // specif smtp server
$mail->SMTPSecure= "ssl"; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected
$mail->SMTPAuth = true;
$mail->Username = "jiansentest@gmail.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password

$mail->AddAddress("jiansenreceive@gmail.com", "Jiansen"); //replace myname and mypassword to yours
$mail->AddReplyTo("jiansentest@gmail.com", "Jiansen");
$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("c:\\temp\\js-bak.sql"); // add attachments
//$mail->AddAttachment("c:/temp/11-10-00.zip");

$mail->IsHTML(true); // set email format to HTML
$mail->Subject = 'test';
$mail->Body = 'test';

if($mail->Send()) {echo "Send mail successfully";}
else {echo "Send mail fail";}

?>
5) Run
 http://localhost/phpmailertest/
We got
SMTP -> FROM SERVER:220 mx.google.com ESMTP uf6sm10363353pac.16 - gsmtp
SMTP -> FROM SERVER: 250-mx.google.com at your service, [207.81.4.41] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:250 2.1.0 OK uf6sm10363353pac.16 - gsmtp
SMTP -> FROM SERVER:250 2.1.5 OK uf6sm10363353pac.16 - gsmtp
SMTP -> FROM SERVER:354 Go ahead uf6sm10363353pac.16 - gsmtp
SMTP -> FROM SERVER:250 2.0.0 OK 1412491179 uf6sm10363353pac.16 - gsmtp
SMTP -> FROM SERVER:221 2.0.0 closing connection uf6sm10363353pac.16 - gsmtp
Send mail successfully

Video: Install PHPMailer 5.2.4 and use smtp gmail 

3 comments:


  1. Fatal error: Uncaught Error: Class 'SMTP' not found in C:\xampp\htdocs\mail\PHPMailer-master\class.phpmailer.php:1466 Stack trace: #0 C:\xampp\htdocs\mail\PHPMailer-master\class.phpmailer.php(1549): PHPMailer->getSMTPInstance() #1 C:\xampp\htdocs\mail\PHPMailer-master\class.phpmailer.php(1486): PHPMailer->smtpConnect(Array) #2 C:\xampp\htdocs\mail\PHPMailer-master\class.phpmailer.php(1323): PHPMailer->smtpSend('Date: Tue, 28 J...', 'test\n') #3 C:\xampp\htdocs\mail\PHPMailer-master\class.phpmailer.php(1203): PHPMailer->postSend() #4 C:\xampp\htdocs\mail\PHPMailer-master\email.php(25): PHPMailer->send() #5 {main} thrown in C:\xampp\htdocs\mail\PHPMailer-master\class.phpmailer.php on line 1466



    always saying like this

    ReplyDelete
  2. plz tell how i solve that problrm

    ReplyDelete