I wrote a method over the past two days to use phpmail (). I thought this method provided by php is very simple, convenient, and easy to use. it is actually not! The phpmail () function needs to be configured before sending an email. below
I wrote a method over the past two days to use php mail (). I thought this method provided by php is very simple, convenient, and easy to use. it is actually not!
The php mail () function must be configured before sending an email. the configuration method is as follows:
If you are not using windows, the sendmail_path command is the only thing you need to worry about. if you are using Windows, you need to check the last two commands.
If you are using Linux or a Unix variant, sendmail_path should look like this:
Or if you use Qmail:
In this instruction in the PHP mail () function, you can also set the configuration parameters to specify the queue buffer options or display the set Return-Path header, as shown below:
As a non-Windows user, this is all you have to do. if you are using Windows, you have more things to do. you also need to take a look at the values of SMTP and sendmail_from. do not confuse sendmail in the sendmail_from command name. although you have not used a program named Sendmail on Windows, it is only the command name. don't be scared by it.
In the result displayed in your phpinfo (), check the default values of SMTP and sendmail_from-they are either blank or contain random values. you should change them to meaningful values.
If you are determined to run an SMTP service program on this computer, your entries in the php. ini file should be as follows: SMTP = localhost
However, if you want to use the external mail server of your ISP (EarthLink in this example), the Mail in php. ini should look as follows: SMTP = mail.earthlink.net
You can also use IP addresses instead of domain names, because computers do not distinguish these two entries.
The second configuration command is sendmail_from, which should be set to the email address in the From header. it can be modified in the script but is usually used as the default value. the following is a sample firstname.lastname@example.org for this configuration directive referring to your own email address, the code is as follows:
Sendmail_from = email@example.com
Send a simple email with the following code:
- $ Txt = "First line of textnSecond line of text ";
- // Use wordwrap () if lines are longer than 70 characters
- $ Txt = wordwrap ($ txt, 70 );
- // Send email
- Mail ("firstname.lastname@example.org", "My subject", $ txt );
At the beginning, I felt very good. NetEase mailbox, QQ mailbox, and GMAIL mailbox can all be received, but HOTMAIL, TOM, LIVE, and other mailboxes cannot receive such emails!
Identity authentication is generally required when a query email is sent, and the mail () provided by PHP is powerless and fragile!