PHPmail () function usage and Configuration Methods

Source: Internet
Author: User
I have been using a third-party email system to send emails, such as QQ

I have been using a third-party email system to send emails, such as QQ

Configuration

To do well, you must first sharpen your tools. First, we will take windows as an example to describe how to configure local mail.

Download the attachment sendmail.zip

-Decompress the package to any path, modify sendmail. ini, and 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

Note:
Currently, the test is successful only by qq. If 163 is unsuccessful, it may be that he has a filtering system that can be successfully sent to gmail.

Syntax

The Code is as follows:

Mail (to, subject, message, headers, parameters)

Definition and usage

The mail () function allows you to send emails directly from scripts.
If the mail is successfully received, true is returned; otherwise, false is returned.
Description
In messages specified by the message parameter, rows must be separated by an LF (\ n. Each line cannot exceed 70 characters.
(IN Windows) when PHP is directly connected to the SMTP server, if a full stop is found at the beginning of a line, it will be deleted. To avoid this problem, replace a single period with two periods.

The Code is as follows:


$ Text = str_replace ("\ n.", "\ n ..", $ text );
?>

Tips and comments

Note: you need to keep in mind that the mail delivery is accepted and does not mean that the mail has reached the planned destination.
Example
The following is an official example of sending HTML emails.

The Code is as follows:


$ To = "somebody@example.com, somebodyelse@example.com ";
$ Subject = "HTML email ";

$ Message ="


HTML email


This email contains HTML Tags!











Firstname Lastname
John Doe



";

// When sending an HTML email, always set content-type
$ Headers = "MIME-Version: 1.0". "\ r \ n ";
$ Headers. = "Content-type: text/html; charset = UTF-8". "\ r \ n ";

// More headers
$ Headers. = 'from: '. "\ R \ n ";
$ Headers. = 'HTTP: myboss@example.com '. "\ r \ n ";

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.