Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to use php to deliver a simple mail. Before I am using WAMP server, however as it does not include a SMTP client/server, so I switch to XAMPP. By using XAMPP, the mail() function returns true this time, however, when I check my gmail mailbox, I cannot receive the mail successfully. My XAMPP is installing on Window Server 2008. Based on what I have read, I think the cause of mail cannot be sent is Window does not have a mail server installed, so I checked in the server manager of Window, however it shows that SMTP server has been installed, so I have no idea what is the cause of the problem.

Here is my PHP code:

$subject = "Simple mail";
$message = "Here is a test mail";
$to = "me@gmail.com";
$from = "me@test.com";
$header = "From: ".$from;

if(mail($to, $subject, $message, $header))
   print "success<br>";
else
   print "fail<br>";

Below is the part about mail in php.ini, I have not made any changes:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = localhost
; smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost  

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.  

; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\php\logs\php_mail.log"

At last here is the picture to show:

Mail server has installed

Mail server starts

Set up mail server with Mercury: Setting up with Mercury

share|improve this question

migrated from stackoverflow.com Jul 27 '12 at 4:17

5 Answers

If mail() returns true, this means PHP has succesfully delivered the message to your smtp mail server (successfully accepted for delivery). From there the server then needs to send it to gmail.

So from this it would mean your smtp server is not correctly configured to send the e-mail. Check your logs for the smtp server to give you more info.

Also you might consider using a component like swift.

share|improve this answer
I have set up it like this, however, when I try to send the mail again, still no log message being shown, winservermart.com/HowTo/SMTP_Logs.aspx I even cannot find the folder SMTPSVC1 – user1502740 Jul 25 '12 at 4:03
try checking C:\xampp\mailoutput. you need to read the configuration options to see what you're actually doing. You're using C:\xampp\mailtodisk\mailtodisk.exe to send the mail, instead of a true smtp server. mailtodisk.exe is simply writing the emails to files instead of actually sending them! – Ben Rowe Jul 25 '12 at 5:45
I find out the mailoutput folder is empty, so none of the email is being sent after the server receives them? Then may I ask what should I do? – user1502740 Jul 25 '12 at 5:50
actually, I just show I have stopped IIS mail server, so Mercury is running at port 25 correctly, so you mean mailtodisk will create a file in my disk but do not deliver it? – user1502740 Jul 26 '12 at 2:47

The problem is in these two lines:

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

The comment is wrong. You actually have to uncomment the line if you want to use mailToDisk. And, since the line is uncommented, all your e-mails are simply being written to disk.

On my XAMPP installation, I found another error in the documentation. It doesn't write the e-mails to C:\xampp\mailoutput. It actually writes them to C:\xampp\tmp\mailoutput.

share|improve this answer
; SMTP = localhost
; smtp_port = 25

You might need to uncomment those 2 lines to tell php where to find the mail server? Assuming of course, the server is on the same machine PHP is installed on.

share|improve this answer
so what I need to do is remove ';'? – user1502740 Jul 25 '12 at 3:58
Yeah, since the ; denotes a start of a comment – Jahufar Jul 25 '12 at 6:09
ok, I understand, but after I make changes and restart the Apache of my XAMPP server, mails still cannot be delivered to the destination – user1502740 Jul 25 '12 at 6:27
From the screen shot you have posted, it seems like you're looking at the wrong server. You said you used Mercury that came bundled with XAMP but you're looking at the mail server that is built into IIS. I've not used PHP on WAMP but you need to look for mercury's admin panel and make sure it's configured correctly (it should look like this: 2.bp.blogspot.com/_PgR77lCbdLw/S2FwLvvAJVI/AAAAAAAAAMw/…) – Jahufar Jul 26 '12 at 2:39
In fact, just go read this: system66.blogspot.com/2010/01/… – Jahufar Jul 26 '12 at 2:40

Quote from manual:

The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

This means you need to use smtp configuration (uncomment lines starting with smtp and edit the values if needed):

SMTP = localhost
smtp_port = 25
share|improve this answer
I have uncommented these lines, but still the same, mail reponse true, but mails cannot be delivered to the destination – user1502740 Jul 25 '12 at 4:08
Do you have a mail server (smtp) running on your local computer? If so, check mailserver logs, if not - make sure you set SMTP to a hostname/ip of the mailserver – poncha Jul 25 '12 at 4:17
I have added a screen capture above, I think the server has been started successfully, there is why I have no idea how should I tackle the problem – user1502740 Jul 25 '12 at 4:20

Remove ';' from the below lines so that

; SMTP = localhost
; smtp_port = 25
;sendmail_from = postmaster@localhost

becomes

SMTP = localhost
smtp_port = 25
sendmail_from = postmaster@localhost

Then open XAMPP control panel and start Mercury mail. Send email again and check your inbox.

UPDATE: Save your php.ini file, go to XAMPP control panel and restart Apache server. Try sending email now.

share|improve this answer
I have followed your way and started Mercury, but still the mail cannot arrive my mail box, from the picture I given out above, my SMTP mail server of Windows should be started, isn't it? – user1502740 Jul 25 '12 at 5:20
Made an update, check it out. Also do you really have an email account as me@gmail.com or are you using an example in your code? – asprin Jul 25 '12 at 5:23
no, me@gmail.com is just an example here, I use my own email address in my code instead – user1502740 Jul 25 '12 at 5:27
when I start Mercury, 1:28:18 PM [mercury] Possible problem detected! 1:28:18 PM [mercury] Port 25 in use by "inetinfo.exe"! Port 25 is being used, I see Mercury also use other ports, so will this causes problem, or it can work fine? – user1502740 Jul 25 '12 at 5:30
I have stopped and restarted my Apache, for sure I have updated the php.ini, I tried to send the mail again, but it still does not work, so is it the problem of the Window email server? if yes, how should I make chagnes on it to solve the problem? – user1502740 Jul 25 '12 at 5:33
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.