• PHP with using Gmail SMTP

    Posted on September 23, 2008 by in Other Technologies

    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

1,633 Responses so far.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>