Case of successful PHP test email sending

Source: Internet
Author: User
Tags php email
This article mainly introduces a successful PHP mail sending case. For more information, see

This article mainly introduces a successful PHP mail sending case. For more information, see

Mail () function: connects to the mail server and uses 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 ('2017 @ 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:

<? Phprequire ('. /PHPMailer/class. phpmailer. php '); $ phpmailer = new PHPMailer (); $ phpmailer-> 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 ()? 'Sending successfully': 'sending failed';?>

The Code is as follows:

<? Php/** use the PHPMailer class for sending steps: 0: Introduction 1: instantiation 2: Configuration Attribute 3: Call to send **/require ('. /PHPMailer/class. phpmailer. php '); $ phpmailer = new PHPMailer ();/* you can use the mail () function under win to set phpmailer to sendmail in linux, the qmail component can use the smtp protocol to log on to an account and send */$ phpmailer-> 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) $ phpmailer-> Password = '';// The password for sending the mailbox // you can send the $ phpmailer-> CharSet = 'utf-8'; $ phpmailer-> From = 'never _ 4ill@163.com '; $ phpmailer-> FromName = 'neverkill '; $ phpmailer-> Subject = 'superstart Aseoe'; $ phpmailer-> Body = 'feet home (focus on front-end development and programming design. '; // set the recipient $ phpmailer-> AddAddress ('never _ 4ill@163.com', 'neverkill '); // Add a CC $ phpmailer-> AddCC ('20140901 ', 'aseoe'); // send the 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 the operation once ).

The above is a successful case of php mail sending, and I hope it will help you learn it.

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.