PHP test successful mail-sending case _php tips

Source: Internet
Author: User

Mail () function: connect to the mail server, use the SMTP protocol, interact with the server, and drop mail.

Attention:

1, mail function does not support the ESMTP protocol,---that is, can only direct investment, can not log

2, by the above, we can only direct to the final recipient server address. And that address, which is specified in php.ini, so we want to send a letter to aseoev@163.com using the mail () function, we have to---

1) Query the address of 163 mail server

2 Write the address into the php.ini.

The PHP instance code is as follows:

SMTP = 163mx02.mxmail.netease.com 
sendmail_from = wusong@192.168.1.100 

But using PHP's own mail function to send mail we need to install a sendmail component in Linux before it can be used.

If you do not have this sendmail component we can use the Phpmailer function to manipulate the example code as follows:

<?php 
 
 require ('./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 ()? ' Send success ': ' Send failed '; 
 
? > 

With no content on top, look at the content with the following code:

<?php 
 
/** 
using the Phpmailer class to 


send a letter step: 
0: Introduce 
1: Instantiate 
2: Configuration attribute 
3: Call sent 
**/ 
require ('./ Phpmailer/class.phpmailer.php '); 
$phpmailer = new Phpmailer (); 
 
/* 
set the way to Phpmailer credit can 
be used under the win Mail () function to use 
Linux under the Sendmail,qmail component can be used to send the 
SMTP protocol to log into an account, to send 
* * 
$phpmailer->ISSMTP ()///////////// 
$phpmailer->host = ' smtp.163.com ' 
with SMTP protocol; $phpmailer->smtpauth = true; 
$phpmailer->username = '; Send the account number of the mailbox (with 163 email letter account) 
$phpmailer->password = ';//Send the password of the mailbox 
//can write a letter 
$phpmailer->charset= ' Utf-8 '; 
$phpmailer->from = ' never_4ill@163.com '; 
$phpmailer->fromname = ' Neverkill '; 
$phpmailer->subject = ' Superstart aseoe '; 
$phpmailer->body = ' cloud-dwelling community (Http://www.jb51.net focuses on front-end development and programming design. ') 
Setting up the addressee 
$phpmailer->addaddress (' never_4ill@163.com ', ' Neverkill '); 
Add a CC 
$phpmailer->addcc (' 1234567 ', ' Aseoe '); 
Letter 
Echo $phpmailer->send ()? ' Ok ': ' Fail '; 

Add a method that uses the example above:

Directly Phpmailer compressed packets into the root directory can be run, directly put the file to the local Wamp root directory, run 02.php Mail can be issued (the premise PHP file executable)-(no words in the root directory to build a folder repeat operation once) http://localhost/02.php.

The above is the PHP to send mail success stories, I hope to help you learn.

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.