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.