"Tamping PHP Basics" php send mail (phpmailer)

Source: Internet
Author: User
Tags php language php basics php send mail word wrap

Address of this article

Reference address

Share an outline:

1. Overview

2. Write code to send mail

3. Reference documentation

1. Overview

This article is about using the Mail class library Phpmailer to send mail methods.

When we do project, we often need the function of the mail. In fact, the PHP language itself already has a way to send mail (mail () method), and do not say that the method to implement a few functions, want to use the mail () method to send the message must be configured on their own SMTP server, here does not speak the use of mail (function call is really simple). Therefore, we recommend using the second method: Phpmailer.

2. Write code to send mail

1) "Download Phpmailer"

First, go to http://phpmailer.sourceforge.net/this address to download the latest Phpmailer package (Phpmailer method must use this package, currently relying on GitHub).

Download the compressed package directly also line: Https://github.com/wozhuzaisi/PHPMailer/archive/master.zip

2) "Code implementation"

Unzip to the appropriate directory when the download is complete. You can see the class.phpmailer.php in the extracted folder (call Phpmailer need to include this file)

Example code:

<?PHP//1. "" Phpmailer:https://github.com/wozhuzaisi/phpmailer/archive/master.zip//2. "Mailbox Configuration SMTP" This article implements 163 mailbox delivery for the SMTP protocol. Other mailboxes and protocols please refer to: http://blog.wpjam.com/m/gmail-qmail-163mail-imap-smtp-pop3///3. "Text encoding" please ensure that the Utf-8 text encoding, otherwise the message will appear garbled//4. " Run as "call Smtp_mail () function directly//test mail//Parameter description (recipient email address, recipient name, message subject, message content, additional information, sender user name)Smtp_mail ("[Email protected]", ' Receiveusername ', "" title "12.01 Test Mail", "Content" test message "," ",$fromUsername= "Mail Sender");Echo"<br>end<br>" ; functionSmtp_mail ($receiveEmailAddress,$receiveUserName,$subject,$body,$extraHdrs= ",$fromUsername){     $path= ' phpmailer-master/'; require_once($path." Class.smtp.php "); require($path." Class.phpmailer.php "); $mail=NewPhpmailer (); $mail-&GT;ISSMTP ();//Send via SMTP//Use 163 mailbox here    $mail->host = "smtp.163.com";//SMTP Servers    $mail->smtpauth =true;//Turn on SMTP authentication        $mail->username = "Youremailusername";//SMTP username Note: Normal mail authentication does not need to add @ domain name here is my 163 mailbox    $mail->password = "Youremailpassword";//SMTP Password Enter the password for the mailbox here        $mail->from =$fromMailAddress= "[email protected]";//Sender Mailbox    $mail->fromname =$fromUsername;//Sender    $mail->charset = "UTF-8";//Specify the character set here! After you specify UTF-8, the title and sender of the message will not be garbled, if the GB2312 title will be garbled    $mail->encoding = "Base64"; $mail->addaddress ($receiveEmailAddress,$receiveUserName);//recipient's mailbox and name    $mail->addreplyto ($fromMailAddress,$fromUsername); //$mail->wordwrap =,//set word wrap word wrapping//$mail->addattachment ("/var/tmp/file.tar.gz");//Attachment        Accessories//$mail->addattachment ("/tmp/image.jpg", "new.jpg");  $mail->ishtml (TRUE); Send As HTML//mail subject    $mail->subject =$subject; //Message Content    $mail->body =$body; //$mail->altbody = "text/html";     if(!$mail-Send ()) {            Echo"Error <p>"; Echo"Error:".$mail-errorinfo; Exit; }        Else {            Echo"Success!"; }    }  

That's all, welcome criticism.

3. Reference documentation

1) Send mail using Phpmailer

2) php send mail (phpmailer)-FTD2012-Blog Park

"Tamping PHP Basics" php send mail (phpmailer)

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.