PHP mail () function usage and configuration method

Source: Internet
Author: User
Tags html tags ini mail

have been using a Third-party mail system to send mail, such as QQ Ah, Gmail Ah, etc., but sometimes customers do not want to give us the sender's mailbox and password, then I found that the use of PHP with the mail function can fully achieve this demand

Configuration

工欲善其事, its prerequisite. First, let's take windows as an example to illustrate how to configure local mail.

Download Attachment Sendmail.zip

-Extract to any path, modify Sendmail.ini, modify the following information as needed.

The code is as follows:

[SendMail]

Smtp_server=smtp.qq.com

Smtp_port=25

Error_logfile=error.log

Debug_logfile=debug.log

auth_username=*** @qq. com

auth_password=***

force_sender=*** @qq. com

-php.ini

[Mail Function]

SMTP = smtp.qq.com

Smtp_port = 25

Sendmail_from = * * * @qq. com

Sendmail_path = "D:/sendmail/sendmail.exe-t-I."

Mail.add_x_header = On

Attention:

The current test is only QQ sent success, 163 of the unsuccessful may be he has a filtering system, can be successfully sent to Gmail.

Grammar

Copy code code as follows: Mail (to,subject,message,headers,parameters)

Definitions and usage

The mail () function allows you to send e-mail directly from a script.

Returns True if the post of the message was successfully received, otherwise false.

Description

In messages specified in the message parameter, the rows must be separated by an LF (n). No more than 70 characters per line.

(under Windows) when PHP connects directly to the SMTP server, if a period is found at the beginning of a line, it is deleted. To avoid this problem, replace a single period with two periods.

The code is as follows:

<?php

$text = Str_replace ("N.", "N..", $text);

?>

Tips and comments

Note: You need to remember that mail delivery is accepted and does not mean that the message arrives at the intended destination.

Example

An official example of sending an HTML message is cited below.

The code is as follows:

<?php

$to = "somebody@example.com, somebodyelse@example.com";

$subject = "HTML email";

$message = "

<title>html email</title>

<body>

<p>this Email contains HTML tags!</p>

<table>

<tr>

<th>Firstname</th>

<th>Lastname</th>

</tr>

<tr>

<td>John</td>

<td>Doe</td>

</tr>

</table>

</body>

";

When you send an HTML e-mail message, always set the Content-type

$headers = "mime-version:1.0". "RN";

$headers. = "Content-type:text/html;charset=utf-8". "RN";

More headers

$headers. = ' From: <webmaster@example.com> '. "RN";

$headers. = ' cc:myboss@example.com '. "RN";

Mail ($to, $subject, $message, $headers);

?>

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.