Under Windows configuration sendmail send mail via PHP mail function

Source: Internet
Author: User

Two types of PHP sending methods

In many PHP programs usually need to send e-mail such as discuz need to choose sendmail Letter, WordPress comment reply need to send a letter, however, there are two different ways of sending mail. One is to send the letter directly through the Mail () function in PHP, but by writing some programs to send it through the STMP service.

The former requires the support of the server on which the program resides, and most often the Linux server has this service. For example, I used the GoDaddy host can send a letter, but the domestic host service providers are basically not with the support of this function. Because in this era of spam, the server provider simply shut down the use of this function, so it is difficult for people to call Mail () to send letters. Specific test you can call <? PHP phpinfo ();?> to see if your server supports this function.

While the latter can achieve the ability to send e-mail, but need to write their own program with the call STMP server use. There are also relevant programs available on the Internet that can be used directly. But after all, there is no mail () function to come directly, come fast. The virtual host user chooses stmp to send the message. If it is a VPS or a server host user is recommended to use the first way.

Today I'll explain how to make mail () in PHP work. Today we mainly explain the use of sendmail in Windows.

SendMail was originally the software of the UNIX department and had good usability in the lamp system. It's a bit difficult to do this under Windows, but like memcached, there are always people who have developed the version that Windows can use. If you are a XAMPP suite user does not need to download, then the inside of the SendMail folder copied to the appropriate place. Otherwise you need to download this.

I put the position is d:/server/sendmail/, it is said that the length of the address can not be too long, or there will be errors. Next, take two steps to configure PHP and sendmail.

Configure PHP.ini

[Mail Function]
SMTP = localhost
Smtp_port = 25
Sendmail_from = [email protected]
Sendmail_path = "D:\sendmail\sendmail.exe-t"

Default state Sendmail_path the front is ";", we need to remove, and then in "" to fill in the Sendmail.exe address, and then add a parameter-T. Sendmail_from =, this seems to be no use, just fill it out.

Configure Sendmail.ini

[sendmail]

smtp_server=smtp.qq.com
smtp_port=25
Smtp_ssl=auto
Error_logfile=error.log
debug_logfile= Debug.log
auth_username=
auth_password=
pop3_server=
pop3_username=
pop3_password=

Smtp_server=, this need to fill out the SMTP server you want to use, you can choose local Build (later the article will explain), you can choose 163, QQ, gmail (if Gmail needs the server to enable Ssl_module Modules) SMTP or POP3 server. Note that the first use of the proposed Debug_logfile=debug.log, remove, so that you can record each time the specific message sent, if an error can be found in Error.log. Auth_username=, auth_password= need to fill in your STMP account information (specific can Google a bit), if it is POP3 the corresponding fill. Fill in a category on it.

Test

After we restart Apache, we can formally take effect. We use a PHP program to test if it takes effect.

<span style= "color:  #f00;" >&lt;? php</span><span style= "color:  #000-2;" > $now </span> <span style= "color:  #000;" >=</span> <span style= "color: # @cm-word;" >date</span> (<span style= "color: # @cm-word;" > "y</span><span style=" color:  #000; " >-</span><span style= "color: # @cm-word;" >m</span><span style= "color:  #000;" >-</span><span style= "color: # @cm-word;" >d</span> <span style= "color: # @cm-word;" >h</span>:<span style= "color: # @cm-word;" >i</span>:<span style= "color: # @cm-word;" >s</span><span style= "color: # @cm-word;" > "</span>", <span style= "color:  #000-2;" > $from _name</span> <span style= "color:  #000;" >=</span> <span style= "color: # @cm-WOrd; " > ' </span><span style= ' color: # @cm-word; " > Test </span><span style= "color: # @cm-word;" > Trial sendmail</span><span style= "color: # @cm-word;" > ' </span>;<span style= ' color:  #000-2; " > $from _email</span> <span style= "color:  #000;" >=</span><span style= "color:  #000-2;" > $headers </span> <span style= "color:  #000;" >=</span> <span style= "color: # @cm-word;" > ' from</span>: <span style= ' color:  #000-2; " > $from _name</span> <span style= "color:  #000;" >&lt;</span><span style= "color:  #000-2;" > $from _email</span><span style= "color:  #000;" >&gt;</span><span style= "color: # @cm-word;" > ' </span>;<span style= ' color:  #000-2; " > $body </span> <span style= "color:  #000;">=</span> <span style= "color: # @cm-word;" > ' </span><span style= ' color: # @cm-word; " > This </span><span style= "color: # @cm-word;" > is </span><span style= "color: # @cm-word;" > A </span><span style= "color: # @cm-word;" > Seal </span><span style= "color: # @cm-word;" > To </span><span style= "color: # @cm-word;" > From </span> <span style= "color:  #000-2;" > $from _name</span> <span style= "color:  #000;" >&lt;</span><span style= "color:  #000-2;" > $from _email</span><span style= "color:  #000;" >&gt; test mail </span>.<span style= "color: # @cm-word;" > ' </span>;<span style= ' color:  #000-2; " > $subject </span> <span style= "color:  #000;" >=</span> <span style= "color: # @cm-word;" > ' </span> [<span style= "color:  #000-2;" > $now </span>]  mail <span style= "color: # @cm-word;" > Test </span><span style= "color: # @cm-word;" > Trial </span><span style= "color: # @cm-word;" > ' </span>;<span style= ' color:  #00f; " >if</span>  (<span style= "color: # @cm-word;" >mail</span> (<span style= "color:  #000-2;" > $to </span>, <span style= "color:  #000-2;" > $subject </span>, <span style= "color:  #000-2;" > $body </span>, <span style= "color:  #000-2;" > $headers </span>))  {<span style= "color:  #00f;" >echo</span> <span style= "color: # @cm-word;" > "success</span><span style=" color:  #000; " >!</span><span style= "color: # @cm-word;" > "&LT;/SPAN&GT;;}  <span style= "color:  #00f;" >else</span>&nbsp {<span style= "color:  #00f;" >echo</span> <span style= "color: # @cm-word;" > "fail</span><span style=" color: # @cm-word; " >...</span><span style= "color: # @cm-word;" > "&LT;/SPAN&GT;;} <span style= "color:  #f00;" >?&gt;</span>


If the letter is successful, it indicates that the SendMail has taken effect. If not successful, look at Error.log, Crash.log, Debug.log related error prompts to debug.

If the server version is newer, you may not be able to use the SendMail program, such as the error I encountered is the message is missing sender's address, how the search did not find a solution, and even did not find a similar content, in this case, then decisively give up. Find a new way, see tomorrow article "10 seconds to let the PHP mail () function successfully e-mail"

Finally post Crash.log content, see a master can solve it?

Date/time:2012-08-12, 00:38:16, 304ms
Allocated memory:3.90 MB
Command line:d:\sendmail\sendmail.exe-t
Executable:sendmail.exe
Exec. Date/time:2011-06-18 01:10
Compiled With:delphi 2006/07
Madexcept version:3.0l
CallStack CRC: $e 1790c4a, $e 1790c4a, $e 1790c4a
Exception number:1
Exception class:exception
Exception message:message is missing sender ' s address.

Main thread ($6D8):
004B59C5 +b11 sendmail.exe sendmail 686 +204 Initialization

Thread $540:
7c957b67 +a Ntdll.dll ntwaitformultipleobjects

Stack Dump:
0012FE04 CA 4b xx de fa ed 0e-01 00 00 00 07 00 00 00. YK ........
0012FE14 (FE) CA 4b 00-e0 4e AA 00 06 00 00 00 ..... YK. N......
0012fe24 (3f) 00-c0 FF (Fe 12 00 .....) A..... 4 ...
0012fe34-FE C8 4b 00-c0 FF 4c FE @[email protected]
0012FE44 5f 4d c0 FF 00-B4 ff C8 4b [email protected]@.
0012fe54 C0 ff, xx 00-00, XX, xx, E0 fd 7f .........
0012fe64 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fe74 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fe84 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fe94 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fea4 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012feb4 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fec4 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fed4 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fee4 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012fef4 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012ff04 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012ff14 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012ff24 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......
0012ff34 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......

disassembling:
[...]
004B59B2 jnz Loc_4b59ca
004B59B4 686 mov ecx, $4b6bc8; ' Message is missing sender ' s address '
004B59B9 mov dl, 1
004B59BB mov eax, [$4085b0]
004B59C0 call-$a 8031 ($40d994); SysUtils.Exception.Create
004b59c5 > call-$b 0cde ($404CEC); [Email protected]
004B59CA 687 CMP DWORD ptr [$4C3F48], 0
004b59d1 jnz loc_4b5a1f
004B59D3 mov eax, [$4c3f78]
004B59D8 mov eax, [eax+$98]
004b59de call-$a 007f ($415964); Classes.TCollection.GetCount
[...]

Under Windows configuration sendmail send mail via PHP mail function


Configure SendMail under Windows to send mail via the PHP mail function

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.