YNDK+LeslieHomepage 歡迎來到演藝特工暨哥哥網站




PHPMailer 1.73 with SSL Support

09 10月 2007
Posted by 匿名者

匿名者's 的頭像

PHPMailer is a great email component for PHP, however, it lacks the support of connecting to SMTP servers that requires SSL (such as GMail). Therefore, I've modified this version to add a "IsSSL()" method to the class to handle this.

Download HERE

Remarks: In order to use SSL SMTP connection, the OpenSSL extension has to be enabled in php.ini:

extension=php_openssl.dll

Sample Code:

<?php
    require("class.phpmailer.php");
    
    $mail = new PHPMailer();
    
    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->IsSSL();
    $mail->Host = "smtp.gmail.com"; // specify main and backup server
    $mail->Port = 465;
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "youruserid@gmail.com"; // SMTP username
    $mail->Password = "yourpassword"; // SMTP password

    $mail->From = "sender@sender.com";
    $mail->FromName = "Sender's Name";
    $mail->AddAddress("recipient@recipient.com", "Recipient's Name");

    $mail->WordWrap = 50; // set word wrap to 50 characters
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
    //$mail->IsHTML(true); // set email format to HTML

    $mail->Subject = "Here is the subject";
    $mail->Body = "This is the HTML message body <b>in bold!</b>";
    //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

    if(!$mail->Send())
    {
     echo "Message could not be sent. <p>";
     echo "Mailer Error: " . $mail->ErrorInfo;
     exit;
    }

    echo "Message has been sent";
?>


Tags: