Main functional features and simple instructions of PHPMailer

  • 2021-01-02 21:47:41
  • OfStack

Support for email s/mime encrypted digital signatures
Support mail multiple TOs, CCs, BCCs and REPLY-ES9en
It works on any server platform, so you don't have to worry about WIN not being able to send email
Support for text /HTML messages
image images can be embedded
Support for mail clients that do not support HTML reading
Powerful send mail debugging function debug
Custom mail header
Redundant SMTP server support
Supports 8bit, base64, binary, and ES29en-ES30en codes
Text wraps automatically
Support multi-attachment sending function
Support for SMTP server validation
Successfully tested on Sendmail, qmail, Postfix, Gmail, Imail, Exchange and other platforms
Provide download files, including detailed documentation and sample instructions, so don't worry about difficult to get started!
The PHPMailer is very small, simple, convenient and fast

The use of PHPMailer (take gmail smtp as an example for sending emails, but also supports other methods such as sendmail pop) :
First of all to http: / / phpmailer. worxware. com/download the latest version of the package
After downloading, find class.phpmailer.php and class.smtp.php and put them in your directory!
And then I'm going to create a new php file and I'm going to call it phpmail.php
phpmail.php is as follows:
I directly wrote the mail sending module as a function postmail(), which can be directly called when you use it. The content of the function is as follows:

The program code


function postmail($to,$subject = "",$body = ""){
    //$to  Represents the recipient address  $subject  Indicates the subject line of the message  $body Represents the body of the message 
    //error_reporting(E_ALL);
    error_reporting(E_STRICT);
    date_default_timezone_set("Asia/Shanghai");// Set time zone east 8 area 
    require_once('class.phpmailer.php');
    include("class.smtp.php"); 
    $mail             = new PHPMailer(); //new1 a PHPMailer Object out 
    $body             = eregi_replace("[\]",'',$body); // Do the necessary filtering of the content of the message 
    $mail->CharSet ="UTF-8";// Set email code, default ISO-8859-1 , this item must be set if sending Chinese, otherwise it is messy 
    $mail->IsSMTP(); //  Set to use SMTP service 
    $mail->SMTPDebug  = 1;                     //  To enable the SMTP debugging 
                                           // 1 = errors and messages
                                           // 2 = messages only
    $mail->SMTPAuth   = true;                  //  To enable the  SMTP  Validation functions 
    $mail->SMTPSecure = "ssl";                 //  Security protocols 
    $mail->Host       = "smtp.googlemail.com";      // SMTP  The server 
    $mail->Port       = 465;                   // SMTP The port number of the server 
    $mail->Username   = "SMTP Server user name ";  // SMTP Server user name 
    $mail->Password   = "SMTP Server password ";            // SMTP Server password 
    $mail->SetFrom(' Sender address, such as admin@domain.com', ' Sender name ');
    $mail->AddReplyTo(" Email return address , Such as admin@domain.com"," The name of the person replying to the email ");
    $mail->Subject    = $subject;
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer! "; // optional, comment out and test
    $mail->MsgHTML($body);
    $address = $to;
    $mail->AddAddress($address, " Recipient name ");
    //$mail->AddAttachment("images/phpmailer.gif");      // attachment 
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent! Congratulations, the email was sent successfully! ";
        }
    }


Related articles: