Phpmailer usage of "PHP mail"

Source: Internet
Author: User
Tags word wrap

First, you need to download the Phpmailer file package Phpmailer. http://phpmailer.sourceforge.net/
Second, confirm that your server system already supports socket, through phpinfo (), check whether sockets is supported (socket is part of PHP extension), if it appears as "enabled", it is supported.
Third, unzip the file into your Web server directory and call the class.
First contains the class.phpmailer.php, then creates the object, sets the parameters, and invokes the member function. See the sample code below for details:
Example 1, make function easy to call

<?PHPrequire("phpmailer/class.phpmailer.php"); functionSmtp_mail ($sendto _email,$subject,$body,$extra _hdrs,$user _name){            $mail=NewPhpmailer (); $mail-&GT;ISSMTP ();//send via SMTP settings (send) using SMTP        $mail->host = "200.162.244.66";//SMTP servers $mail->host = "smtp1.example.com;smpt2.example.com"; Specify primary and secondary servers        $mail->smtpauth =true;//Turn on SMTP authentication open SMTP authentication        $mail->username = "Yourmail";//SMTP username Note: Normal mail authentication does not need to add @ domain name        $mail->password = "MailPassword";//SMTP Password        $mail->from = "[email protected]";//Sender Mailbox        $mail->fromname = "Administrator";//Sender              $mail->charset = "GB2312";//Specify the character set here!         $mail->encoding = "Base64"; $mail->addaddress ($sendto _email, "username");//recipient's mailbox and name        $mail->addreplyto ("[Email protected]", "yourdomain.com");  $mail->wordwrap = +; //Set word wrap word wrapping $mail->addattachment ("/var /tmp/file.tar.gz ");    Attachment Annex $mail->addattachment ("/tmp/image.jpg", "new.jpg"); //Attachment accessories          $mail->ishtml (true);//Send As HTML        $mail->subject =$subject; //Mail subject         //Message Content        $mail->body = ""Content-language" content= "ZH-CN"> <meta http-equiv="Content-type" content= "text/html; charset=gb2312 "> "; $mail->altbody = "Text/html"; if(!$mail-Send ()) {                Echo"Email sent incorrectly <p>"; Echo"Message error message:".$mail-errorinfo; Exit; }            Else {                Echo"$user _nameMessage sent successfully!<br/> "; }        }        //parameter description (sent to, message subject, message content, additional information, user name)Smtp_mail ("[Email protected]", "Welcome to use phpmailer! "," NULL "," yourdomain.com "," username "); ?>

What to note:


   1. The character set of the message, $mail->charset = "GB2312"; Specify the character set here! Here I only specify as GB2312 because so Outlook can display the subject of the message normally, I tried to set it to utf-8 but the garbled characters appear under Outlook.
2. If the message is sent in HTML format, then remember to also specify <meta ... charset=gb2312 ">
3. If you want to use it for mass mailing, remember to modify the include file functions, such as:
require ("phpmailer/class.phpmailer.php");
instead
require_once ("phpmailer/class.phpmailer.php");
Otherwise, a redefinition of the class is generated.


The above code is a reference

after the use of the afternoon, personally think to use Phpmailer,
first, you need to have a mail server
The PHP mail function is not specified and should be used by the PHP settings of the SMTP

and here we need to specify the specific
You also need to specify the manager and password of the mail server

Phpmailer usage of "PHP mail"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.