Phpmailer sending mail

Source: Internet
Author: User

1. First set up a mail to send the mailbox, here to test 163 mailboxes.

After logging in, open the pop3/smtp/service in the settings. (usually after the authorization code is set, 163 of the mailbox system will automatically open this service for you)

2. Download the Phpmail class file

Http://webscripts.softpedia.com/script/PHP-Clases/PHPMailer-Codeworx-Technologies-46188.html

3. Code

<?PHP//include ("./phpmailer/class.phpmailer.php");require"./phpmailer/phpmailerautoload.php";$mail=NewPhpmailer ();$mail-&GT;ISSMTP ();//Enable smtp//$mail->smtpdebug=1;//Open Debug mode//$mail->smtpsecure = "SSL";$mail->charset= ' Utf-8 ';//Set message encoding format$mail->host= "smtp.163.com;";//the name of the SMTP server (this is the case with 163 mailboxes)$mail->smtpauth =true;//Enable SMTP authentication$mail->username = "******";//your mailbox name can not write @ suffix, can also write$mail->password = "******";//mailbox Password, now open mailbox SMTP is called security Code$mail->port=25;//SMTP port number//$mail->port = 994;$mail->setfrom ("******@163.com", "AA");//Sender address (that is, your email address) and sender name$mail->addaddress ("****** @qq. com", "");//recipient address and name$mail-WordWrap= 100;//set character length per line$mail->ishtml (true);//whether HTML-formatted messages$mail->subject = "Test";//Message Subject$mail->body = "Ceshiceshi";//message content//$mail->altbody = "This is a plain text body in a non-profit HTML email client";//message body does not support alternate display of HTMLVar_dump($mail->send ());//Send method, send successful return true, failed to return False//echo $mail->errorinfo;//Get error message

Another example:

<?PHPrequire ' phpmailerautoload.php ';// loading these 1 files and loading the following 2 files is equivalent to //require_once ' class.phpmailer.php ';//require_once ' class.smtp.php ';$mail=NewPhpmailer ();$mail-&GT;ISSMTP ();//using the SMTP service$mail->charset = "UTF8";//encoding format is UTF8, do not set the encoding, Chinese will appear garbled$mail->host = "smtp.163.com";//SMTP server address for sender$mail->smtpauth =true;//whether to use authentication$mail->username = "[email protected]";//Sender's 163 mailbox user name$mail->password = "******";//Sender's mailbox password, note with 163 mailbox here is filled out is "client authorization password" instead of the mailbox login password! $mail->smtpsecure = "SSL";//using the SSL protocol method$mail->port = 994;//163 The SSL protocol port number for the mailbox is 465/994$mail->setfrom ("[Email protected]", "Mailer");//set sender information, such as the sender in the message format description, shown here as mailer ([email protected]), Mailer as a name$mail->addaddress ("[Email protected]", ' Liang ');//set recipient information, such as the recipient in the message format description, shown here as Liang ([email protected])$mail->addreplyto ("[Email protected]", "Reply");//set the reply person information, refers to the recipient after receiving the message, if you want to reply, the reply message will be sent to the email address$mail-&GT;ADDCC ("[email protected]");//set mail cc person, can write address only, the above settings can also be write-only address$mail-&GT;ADDBCC ("[email protected]");//set a secret cc person$mail->addattachment ("bug0.jpg");//Add an attachment$mail->subject = "This is a test mailxx";//message Header$mail->body = "This is the HTML Body <b>very stronge very strong </b>";//message body//$mail->altbody = "This is the plain text plain text";//This is to set the text-only display of the body content, if not supported by HTML, it will be used, basically uselessif(!$mail->send ()) {//Send mail    Echo"Message could not being sent."; Echo"Mailer Error:".$mail->errorinfo;//Output error message}Else{    Echo' Message has been sent. ';}

4. Fill in the data, run the file, and send it successfully.

Phpmailer sending 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.