PHP mail sending example, tested successfully

Source: Internet
Author: User
I have introduced a lot of PHP mail sending examples, but almost all of them are sent using the phpmailer mail plug-in. Below is an example of a successful test of Mail sending. in win, use the mail function of PHP to send emails. the mail () function... I have introduced a lot of PHP mail sending examples, but almost all of them are sent using the phpmailer mail plug-in. Below is an example of a successful test of Mail sending.

In win, use the mail function of PHP to send emails.

The mail () function is used to connect to the mail server and use the smtp protocol to interact with the server and send emails.

Note:

1: The mail function does not support esmtp. --- that is, it can only be directly cast and cannot be logged on.

2: From the above, we can only direct to the final receiving server address. the address is in PHP again. ini specified, so we want to use the mail () function to send mail to the aseoev@163.com, we want ---

1: query the address of the 163 mail server

2: write the address to php. ini.

The php instance code is as follows:

SMTP =  163mx02.mxmail.netease.com sendmail_from = wusong@192.168.1.100 var_dump(mail('597417106@qq.com','from php mail function','very intresting'));

However, to use the mail function provided by php to send emails, we need to install a sendmail component in linux. Otherwise, it cannot be used.

If you do not have this sendmail component, you can use the phpmailer function to operate it. The example code is as follows:

 IsSMTP (); $ phpmailer-> Host = 'smtp .163.com '; $ phpmailer-> SMTPAuth = true; $ phpmailer-> Username = ''; $ phpmailer-> Password = ''; $ phpmailer-> CharSet = 'utf-8'; $ phpmailer-> From =''; $ phpmailer-> FromName = ''; $ phpmailer-> Subject = ''; $ phpmailer-> Body =''; $ phpmailer-> AddAddress ('never _ kiss@163.com ', 'aseoe '); echo $ phpmailer-> send ()? 'Sent successfully': 'failed to send ';

The content is not included in the preceding figure. the code is as follows:

 IsSMTP (); // use the smtp protocol to send $ phpmailer-> Host = 'smtp .163.com '; $ phpmailer-> SMTPAuth = true; $ phpmailer-> Username = ''; // account used to send emails (account used to send emails in 163 email) $ phpmailer-> Password = ''; // send the email password // you can send the $ phpmailer-> CharSet = 'utf-8'; $ phpmailer-> From = 'never _ kill@163.com '; $ phpmailer-> FromName = 'neverkill '; $ phpmailer-> Subject = 'superstart Aseoe'; $ phpmailer-> Body = 'http: // www.phprm.com/-focus on front-end development and PHP Programming Design. '; // Set the recipient $ Phpmailer-> AddAddress ('never _ kill@163.com ', 'neverkill'); // add a CC $ phpmailer-> AddCC ('2017 @ qq.com ', 'aseoe '); // send echo $ phpmailer-> send ()? 'OK': 'fail ';

Add a method to use the preceding example:

Directly decompress the phpmailer package and put it in the root directory to run. directly put the file in the local wamp root directory and run the 02.php email to send it (the php file can be executed) -(if not, create a folder in the root directory and repeat it once) http: // localhost/02. php.

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.