Skip to content


PHP with using Gmail SMTP

If you want to use gmail smtp server in PHP, php mailer is a good choice for you. Here is the example:

include(“class.phpmailer.php”);
$mail = new PHPMailer ();
$mail->IsSMTP ();
$mail->SMTPAuth   = true;
$mail->SMTPSecure = “ssl”;
$mail->Host = “smtp.gmail.com”;
$mail->Port  = 465;
$mail->Mailer= “smtp”;
$mail->Username   = “username@gmail.com”;
$mail->Password   >= “password”;
$mail->AddReplyTo (“Reply Email”, “Recipient Name”);
$mail->From = “sender@gmail.com”;
$mail->FromName = “Sender Name”;
$mail->Subject = “Email Subject”;
$mail->Body = “Email Content…”;
$mail->WordWrap = 50;
$mail->AddAddress (“receiver@gmail.com”, “Receiver Name”);
$mail->IsHTML (true);
$mail->Send ();

However, these simple codes could only work on PHP with enabling the ssl function. If not, you will probably find the warning message in the log file:

Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)

To solve this problem, you have to make sure your php.ini including extension=php_openssl.dll (of course the file should be placed in php extension directory) and copy both libeay32.dll and ssleay32.dll from php directory to apache bin directory.

References:

http://blog.sunflier.com/?p=572

Posted in Other Technologies.

Tagged with , , , .


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Gabe says

    Just wanna say thanks for the information. I’ve spent days trying to configure PHPMailer and finally found this site which helped me out. Thanks a bunch bro.

  2. Way says

    You are welcome. I have also spent a day for that problem.



Some HTML is OK

or, reply to this post via trackback.