Detailed code for sending messages using Phpmailer

Source: Internet
Author: User
Tags set time email account

I. Reasons for sending mail using Phpmailer

PHP has a built-in mail () method, but because some host space does not support this method, you often encounter situations where mail cannot be sent.

Therefore, you can download the Phpmailer class for mail delivery.

Second, the specific steps to send the message

1, first ensure that the sender's mailbox opened the SMTP service.

Set here, as follows:

Set it up and then look down,

2. Download the Phpmailer, copy the class.phpmailer.php and class.smtp.php to the project directory

sendmail.php

<?PHP/** * 2014-08-25 * Description: PHP mail Send * use Phpmailer class * Send attachments, multi-person send * Send attachments * When sending attachments, due to the speed of local network and server, if not properly uploaded, modify PHP with Memory_limit restrictions in the file * * Other possible restrictions post_max_size upload_max_filesize * may also be max_execution_time modified * Please use the email account to confirm the email opened s MTP*/      Set_time_limit(0);//if uploading an attachment card, modify the script execution limit time to 0     require'./class.phpmailer.php '; require'./class.smtp.php '; Date_default_timezone_set ("Asia/shanghai");//Set time zone East zone eight     $mail=NewPhpmailer ();//set up a mail sending class     $mail-&GT;ISSMTP ();//send using SMTP form     $mail->charset= ' Utf-8 ';//Coding     $mail->smtpdebug = 1;//Enable SMTP debugging features//1 = errors and messages 2 = Messages only          $mail->smtpauth =true;//enable the SMTP authentication feature     $mail->host= ' smtp.qq.com ';//QQ SMTP server, send mailbox account company's SMTP server     $mail->port=25;   Port number of the//SMTP server                                      $mail->username= ' [email protected] '; Fill out your email account here$mail->password= ' ******** '; Fill in the password of the sending mailbox here$mail->addaddress (' [email protected] ', ' Bo Wright 2 '); //$mail->addaddress (' [email protected] ', ' Aeolian Crossing '); #多人发送     $mail-ishtml (); //$a = $mail->addattachment (' D:\wamp\www\user.sql ', ' z.zip ');//absolute position of the attachment, name of the attachment after uploading     $mail->subject= ' sent from Phpmailer's mailbox '; $mail->from= ' [email protected] ';//sender's name and address     $mail->fromname= ' Aeolian crossing '; $mail->body= ' Test 4 '; $mail->altbody= ' Additional information '; if(!$mail-Send ()) {       Echo' Mail send failed '. ' </br> '; Echo' Cause of error '.$mail-errorinfo; }Else{        Echo' Mail sent successfully '; }    ?>

This will be OK, can be tested.

If there is a problem with the following figure, it is that the SMTP service is not set up on the outgoing mailbox. You can set it up

Detailed code for sending messages using 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.