PHP Mail Send example (tested successfully)

Source: Internet
Author: User
Tags ini php file php programming require

Under Win,

Use PHP's mail function to send mail

The role of the Mail () function:
is to connect to the mail server
Use the SMTP protocol to interact with this server
and cast mail

Attention:
The 1:mail function does not support the ESMTP protocol,---that is, it can only be directly cast and cannot log in
2: From the above, we can only direct to the final recipient server address.
And the address is specified in the php.ini.


So we want to send a letter to aseoev@163.com using the mail () function.
We're going to---.
1: Query the address of 163 mail servers
2: Write the address into the php.ini.

The code is as follows Copy Code

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

Var_dump (Mail (' 597417106@qq.com ', ' from PHP mail function ', ' very intresting '));

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 don't have this sendmail component we can use the Phpmailer function to manipulate

Example

The code is as follows Copy Code
<?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 it, look at the contents below

<?php


/**
Use Phpmailer class to send letters

The code is as follows Copy Code

Steps:
0: Introducing
1: Instantiating
2: Configuration Properties
3: Call Send

**/

Require ('./phpmailer/class.phpmailer.php ');

$phpmailer = new Phpmailer ();


/*
Set the way Phpmailer credit
You can use the win under Mail () function to send
Linux can be used under the Sendmail,qmail components to send
You can use the SMTP protocol to log on to an account to send
*/

$phpmailer->issmtp (); Use SMTP protocol to send

$phpmailer->host = ' smtp.163.com ';
$phpmailer->smtpauth = true;
$phpmailer->username = '; Send the account number of the mailbox (with 163 email letter account number)
$phpmailer->password = '; Password to send a mailbox

We can send a letter.
$phpmailer->charset= ' Utf-8 ';
$phpmailer->from = ' never_kill@163.com ';
$phpmailer->fromname = ' Neverkill ';
$phpmailer->subject = ' Superstart Aseoe ';
$phpmailer->body = ' http://www.111cn.net/Resource Network-focus on front-end development and PHP programming design. '

Set up the addressee.
$phpmailer->addaddress (' never_kill@163.com ', ' Neverkill ');
Add a CC
$phpmailer->addcc (' 597417106@qq.com ', ' Aseoe ');

Letter

echo $phpmailer->send ()? ' Ok ': ' Fail ';

Add a method that uses the example above

Directly unzip the Phpmailer compression pack into the root directory to run

Directly put the file to the local Wamp root directory, run 02.php Mail can be issued (the premise PHP file executable)-(not a word in the root directory to create a folder repeat operation)

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.