Sendmail problem w/ PHP Form submit

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Sendmail problem w/ PHP Form submit

Postby gshiga » 15. May 2009 10:25

Hi Everyone,

I've installed my first test server on my desktop (Windows XP SP3) using XAMPP Windows 1.7.1 [Basic Package] using the Installer. After installation, I set-up a virtual host for one website. The installation went smooth (status for all components were "Activated", except for FTP Service), and my virtual host also worked fine.

Problem: The problem is that I've tried to forward an email via smtp through a basic contact form using the email() function in a PHP script, but no email is being sent (even though I am successfully being redirected to a thank you header() page after I submit the form). My ISP is godaddy. I've been reading the forum for the past week for solutions, but I can't seem to solve the problem. The following are the forum posts that I found helpful:

viewtopic.php?f=16&t=34510&p=140323&hilit=sendmail#p140323
viewtopic.php?t=24816

After reading the above posts, I did the following:

1. php.ini File: I modified the [mail function] portion of the php.ini File as follows (I also included the MS-DOS bug fix for spaces in the sendmail_path ("~1"):
Code: Select all
[b]Note: The php.ini File was located at \xampp\php\php.ini and NOT at xampp\apache\bin\php.ini. [/b]

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
sendmail_from = info@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\Documents~1and~1Settings\Owner\Desktop\Online~1Test~1Site\Test~1Server\xampp\sendmail\sendmail.exe -t"

; 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 =


2. sendmail.ini File: I modified the sendmail.ini File as follows:

Code: Select all
Note: The sendmail.ini File was located at \xampp\sendmail\sendmail.ini.

[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=smtpout.secureserver.net

; smtp port (normally 25)

smtp_port=25

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

;default_domain=local

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username=info@example.com
auth_password=***password

; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines

pop3_server=pop.secureserver.net
pop3_username=info@example.com
pop3_password=***password

; to force the sender to always be the following email address, uncomment and
; populate with a valid email address.  this will only affect the "MAIL FROM"
; command, it won't modify the "From: " header of the message content

;force_sender=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting.  you can manually set the ehlo/helo name if required

;hostname=localhost


3. HOSTS File: I modified the HOSTS file as follows:
Code: Select all
Note: The HOSTS File was located at C:\windows\system32\drivers\etc\HOSTS.

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost
127.0.0.1        example.com


4. httpd-vhosts.conf File: I modified the httpd-vhosts.conf File as follows:
Code: Select all
Note: The httpd-vhosts.conf File was located at \xampp\apache\conf\extra\httpd-vhosts.conf.

##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host2.example.com
##    DocumentRoot /www/docs/dummy-host2.example.com
##    ServerName dummy-host2.example.com
##    ErrorLog @rel_logfiledir@/dummy-host2.example.com-error_log
##    CustomLog @rel_logfiledir@/dummy-host2.example.com-access_log common
##</VirtualHost>

NameVirtualHost *:80
   <VirtualHost *:80>
    DocumentRoot "C:\Documents and Settings\Owner\Desktop\Online Test Site\Test Server\xampp\htdocs"
         ServerName localhost
   </VirtualHost>

   <VirtualHost *:80>
    DocumentRoot "C:\Documents and Settings\Owner\Desktop\Online Test Site\Test Server\xampp\example.com\website"
    ServerName example.com
   <Directory "C:\Documents and Settings\Owner\Desktop\Online Test Site\Test Server\xampp\example.com\website">
   Options Indexes FollowSymLinks Includes ExecCGI
    Order allow,deny
    Allow from all
   </Directory>
   </VirtualHost>


5. PHP Script: My form action runs the following PHP script to send the email:

Code: Select all
<?php

    /* Email Variables */

   $webMaster = 'info@example.com';
   
   /* Gathering Data Variables */

   $firstname = $_POST['firstname'];
   $lastname = $_POST['lastname'];
   $emailaddress = $_POST['emailaddress'];
   $confirmemail = $_POST['confirmemail'];
   $subject = $_POST['subject'];
   $message = $_POST['message'];
   $termsofuse = $_POST['termsofuse'];
   
   /* Message to $webMaster */

   $body = <<<EOD
<br/><hr/><br/>
First Name: $firstname <br/>
Last Name: $lastname <br/>
<p>Email: $emailaddress </p>
<p>Subject: $subject </p>
<p>Message: $message </p>
<p>Terms of Use: $termsofuse </P>
EOD;

   /* Email Commands */
   $headers = "From: $emailaddress\r\n";
   $headers .= "Content-type: text/html\r\n";
   mail($webMaster, $subject, $body, $headers);
   
   /* Redirect Command */
   header("location:thank-you.shtml");         
 
?>


I've also set-up my MS Outlook to receive email from the same godaddy ISP account and that works fine (I also have that set to use port 25). (I'm not sure if my virtual host on xampp being set to port *80 causes any conflict with the sendmail using port 25?)

Sorry about the lengthy message, but hopefully the detail will help other newbies like myself that need a lot of detail to follow along.

Thank you in advance for any help! :D

Genji
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 15. May 2009 10:46

using the email() function in a PHP script, but no email is being sent

I guess you mean mail()?

(I also included the MS-DOS bug fix for spaces in the sendmail_path ("~1"):

What's this? And if you are want use "~1", you should use real 8.3 names.

Of course, if the preconfigured path is not working, you have found a new bug in PHP...

Code: Select all
sendmail_path = "C:\Documents~1and~1Settings\Owner\Desktop\Online~1Test~1Site\Test~1Server\xampp\sendmail\sendmail.exe -t"

I don't think PHP can start sendmail with this path... Just revert your change and test again. And also look into Apaches' error.log.

Code: Select all
error_logfile=error.log
debug_logfile=debug.log

If PHP can start sendmail, there must be something in one of these logs which gives you more glues about the problem.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby gshiga » 15. May 2009 11:27

Hi Wiedmann,

Thank you for your quick reply.

Your're right ... I meant mail() (and not email ()).

As you recommended, I changed the sendmail_path back to the original path without the "~1" for the spaces.

After I restarted Apache, I tried submitting the form and sending mail(), but still no luck.

error.log: I checked the error.log and this is what it contained:
Code: Select all
[Fri May 15 03:06:16 2009] [warn] pid file C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Fri May 15 03:06:16 2009] [notice] Digest: generating secret for digest authentication ...
[Fri May 15 03:06:16 2009] [notice] Digest: done
[Fri May 15 03:06:17 2009] [notice] Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 configured -- resuming normal operations
[Fri May 15 03:06:17 2009] [notice] Server built: Dec 10 2008 00:10:06
[Fri May 15 03:06:17 2009] [notice] Parent: Created child process 4184
[Fri May 15 03:06:20 2009] [notice] Digest: generating secret for digest authentication ...
[Fri May 15 03:06:20 2009] [notice] Digest: done
[Fri May 15 03:06:22 2009] [notice] Child 4184: Child process is running
[Fri May 15 03:06:22 2009] [notice] Child 4184: Acquired the start mutex.
[Fri May 15 03:06:22 2009] [notice] Child 4184: Starting 250 worker threads.
[Fri May 15 03:06:22 2009] [notice] Child 4184: Starting thread to listen on port 443.
[Fri May 15 03:06:22 2009] [notice] Child 4184: Starting thread to listen on port 80.
[Fri May 15 03:06:49 2009] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/example.com/website/chapters/home/images, referer: http://example.com/chapters/home/contact/contact-us.php
[Fri May 15 03:06:52 2009] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/example.com/website/chapters/home/images, referer: http://example.com/chapters/home/contact/contact-us.php
'C:\Documents' is not recognized as an internal or external command,
operable program or batch file.
[Fri May 15 03:07:13 2009] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/example.com/website/chapters/home/images, referer: http://example.com/chapters/home/contact/thank-you.shtml


I tried running a search for "debug.log", but no file exists.

Unfortunately, I can't make any sense of the error.log. Any ideas?
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 15. May 2009 11:45

'C:\Documents' is not recognized as an internal or external command, operable program or batch file.

It seams, PHP have really a problem with the space. Must test this... (to be continued).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 15. May 2009 12:14

Wiedmann wrote:if the preconfigured path is not working, you have found a new bug in PHP...

OK, there is a bug. :-/

Wiedmann wrote:And if you are want use "~1", you should use real 8.3 names.

Of course, using 8.3 names is working for me.

Code: Select all
sendmail_path = "C:\Documents~1and~1Settings\Owner\Desktop\Online~1Test~1Site\Test~1Server\xampp\sendmail\sendmail.exe -t"

Please verify this path is correct.
(8.3 is not replacing spaces with "~1".)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby gshiga » 15. May 2009 21:45

The following is the path to the sendmail.exe file:

C:\Documents and Settings\Owner\Desktop\Online Test Site\Test Server\xampp\sendmail\sendmail.exe

I'm not familiar with 8.3 names, but I went ahead and changed the sendmail_path in the php.ini file to (I'm not sure if this is correct):

sendmail_path = "C:\Docume~1\Owner\Deskto~1\Online~1\TestSe~1\xampp\sendma~1\sendma~1.exe -t"

(Although I changed the sendmail_path in the php.ini file, I kept the actual file name unchanged.)

After I changed the sendmail_path (and restarting Apache), I tried to submit the form and send the mail() message, but still no luck. Here's the error.log:
Code: Select all
[Fri May 15 13:11:24 2009] [warn] pid file C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Fri May 15 13:11:24 2009] [notice] Digest: generating secret for digest authentication ...
[Fri May 15 13:11:24 2009] [notice] Digest: done
[Fri May 15 13:11:37 2009] [notice] Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 configured -- resuming normal operations
[Fri May 15 13:11:37 2009] [notice] Server built: Dec 10 2008 00:10:06
[Fri May 15 13:11:37 2009] [notice] Parent: Created child process 3988
[Fri May 15 13:11:40 2009] [notice] Digest: generating secret for digest authentication ...
[Fri May 15 13:11:40 2009] [notice] Digest: done
[Fri May 15 13:11:42 2009] [notice] Child 3988: Child process is running
[Fri May 15 13:11:42 2009] [notice] Child 3988: Acquired the start mutex.
[Fri May 15 13:11:42 2009] [notice] Child 3988: Starting 250 worker threads.
[Fri May 15 13:11:42 2009] [notice] Child 3988: Starting thread to listen on port 443.
[Fri May 15 13:11:42 2009] [notice] Child 3988: Starting thread to listen on port 80.
[Fri May 15 13:12:20 2009] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/example.com/website/chapters/home/images, referer: http://example.com/chapters/home/contact/contact-us.php
[Fri May 15 13:12:24 2009] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/example.com/website/chapters/home/images, referer: http://example.com/chapters/home/contact/contact-us.php
The system cannot find the path specified.
[Fri May 15 13:12:57 2009] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Owner/Desktop/Online Test Site/Test Server/xampp/example.com/website/chapters/home/images, referer: http://example.com/chapters/home/contact/thank-you.shtml


The good news is that the previous error message did not appear ("'C:\Documents' is not recognized as an internal or external command,
operable program or batch file.") in the current error log, but the message still didn't get sent.

I'm confused? Thanks for your help!
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 16. May 2009 07:31

The good news is that the previous error message did not appear

You still have the error:
Code: Select all
The system cannot find the path specified.


I'm not familiar with 8.3 names, but I went ahead and changed the sendmail_path in the php.ini file to (I'm not sure if this is correct):
sendmail_path = "C:\Docume~1\Owner\Deskto~1\Online~1\TestSe~1\xampp\sendma~1\sendma~1.exe -t"

Should be also wrong.

The following is the path to the sendmail.exe file:
C:\Documents and Settings\Owner\Desktop\Online Test Site\Test Server\xampp\sendmail\sendmail.exe

Save the following code as GetShortPath.vbs and execute it:
Code: Select all
Option Explicit
Dim fso, f, path

path = "C:\Documents and Settings\Owner\Desktop\Online Test Site\Test Server\xampp\sendmail\sendmail.exe"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(path)
WScript.Echo f.ShortPath
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby gshiga » 20. May 2009 07:56

Hi Wiedmann,

Thank you for the GetShortPath.vbs script. I executed the script and it output the short path. I revised the sendmail_path in the php.ini file to reflect the short path, and tried to submit an email using my contact form. Unfortunately, the message did not send and the following is the error message from my error.log:
Code: Select all
"sendmail: Error during delivery: Sorry, your envelope sender is in my badmailfrom list."


I'm not sure what the error message means, but the following is the PHP script for sending the form (I already posted the same script above):

Code: Select all
<?php

    /* Email Variables */

   $webMaster = 'info@example.com';
   
   /* Gathering Data Variables */

   $firstname = $_POST['firstname'];
   $lastname = $_POST['lastname'];
   $emailaddress = $_POST['emailaddress'];
   $confirmemail = $_POST['confirmemail'];
   $subject = $_POST['subject'];
   $message = $_POST['message'];
   $termsofuse = $_POST['termsofuse'];
   
   /* Message to $webMaster */

   $body = <<<EOD
<br/><hr/><br/>
First Name: $firstname <br/>
Last Name: $lastname <br/>
<p>Email: $emailaddress </p>
<p>Subject: $subject </p>
<p>Message: $message </p>
<p>Terms of Use: $termsofuse </P>
EOD;

   /* Email Commands */
   $headers = "From: $emailaddress\r\n";
   $headers .= "Content-type: text/html\r\n";
   mail($webMaster, $subject, $body, $headers);
   
   /* Redirect Command */
   header("location:thank-you.shtml");         

?>


Please note that I use GoDaddy.com for ISP, and I uploaded the same PHP script (and html form) onto their server last weekend and it successfully sent a message.

Thanks again for all your help.
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 20. May 2009 08:13

Code: Select all
"sendmail: Error during delivery: Sorry, your envelope sender is in my badmailfrom list."

You should enable "force_sender" in your "sendmail.ini" (usually set to auth_username).

BTW:
Sure your ISP is using pop3 before smtp? (it's not common to enable the pop3_* options.)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby gshiga » 20. May 2009 08:32

Thanks for your quick response.

I enabled the force_sender in my sendmail.ini file, and set it to force_sender=info@example.com (same as auth_username). Afterwards, I tried sending a message with pop3 options enabled and disabled, and I received the same error.log both times:

Code: Select all
"sendmail: Error during delivery: Sorry, that domain isn't in my list of allowed rcpthosts."


Thank you.
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 20. May 2009 08:47

Code: Select all
smtp_server=smtpout.secureserver.net
auth_username=info@example.com
auth_password=***password
force_sender=info@example.com

These are the same settings, you are using in e.g. Outlook/Thunderbird to send mails?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby gshiga » 20. May 2009 08:56

I use the same settings in Outlook and they work (I got the settings from my ISP).

However, Outlook does not have a force_sender field/option.

Can there be a problem with my sendmail.exe file?

Thanks.
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 20. May 2009 09:03

Did you have a debug.log for such a message?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Sendmail problem w/ PHP Form submit

Postby gshiga » 20. May 2009 09:16

The following is from the debug.log in the sendmail folder:

Code: Select all
09/05/20 00:25:00 ** --- MESSAGE BEGIN ---
09/05/20 00:25:00 ** To: info@example.com
09/05/20 00:25:00 ** Subject: Other
09/05/20 00:25:00 ** From: example@yahoo.com
09/05/20 00:25:00 ** Content-type: text/html
09/05/20 00:25:00 **
09/05/20 00:25:00 **
09/05/20 00:25:00 ** <br/><hr/><br/>
09/05/20 00:25:00 ** First Name: Name <br/>
09/05/20 00:25:00 ** Last Name: Name <br/>
09/05/20 00:25:00 ** <p>Email: example@yahoo.com </p>
09/05/20 00:25:00 ** <p>Subject: Other </p>
09/05/20 00:25:00 ** <p>Message: Test message.  </p>
09/05/20 00:25:00 ** <p>Terms of Use: on </P>
09/05/20 00:25:00 ** --- MESSAGE END ---
09/05/20 00:25:00 ** Authenticating with POP3 server
09/05/20 00:25:01 ** Connected.
09/05/20 00:25:01 << +OK <19639.1242804298@p3pop01-11.prod.phx3.gdg><EOL>
09/05/20 00:25:01 >> CAPA<EOL>
09/05/20 00:25:01 << -ERR authorization first<EOL>
09/05/20 00:25:01 >> USER info@example.com<EOL>
09/05/20 00:25:01 << +OK <EOL>
09/05/20 00:25:01 >> PASS Password****<EOL>
09/05/20 00:25:01 << +OK <EOL>
09/05/20 00:25:01 >> QUIT<EOL>
09/05/20 00:25:02 << +OK <EOL>
09/05/20 00:25:02 ** Disconnected.
09/05/20 00:25:02 ** Disconnected.
09/05/20 00:25:02 ** Disconnected.
09/05/20 00:25:02 ** Connecting to smtpout.secureserver.net:25
09/05/20 00:25:02 ** Connected.
09/05/20 00:25:02 << 220 p3plsmtpa01-06.prod.phx3.secureserver.net ESMTP<EOL>
09/05/20 00:25:02 >> EHLO VALUED-B4B48255<EOL>
09/05/20 00:25:02 << 250-p3plsmtpa01-06.prod.phx3.secureserver.net<EOL>
09/05/20 00:25:02 ** Authenticating as info@example.com
09/05/20 00:25:02 >> MAIL FROM: <info@example.com><EOL>
09/05/20 00:25:02 << 250-AUTH LOGIN PLAIN<EOL>250-8BITMIME<EOL>250 PIPELINING<EOL>
09/05/20 00:25:02 >> RCPT TO: <info@example.com><EOL>
09/05/20 00:25:02 << 250 Sender accepted.<EOL>
09/05/20 00:25:02 >> DATA<EOL>
09/05/20 00:25:02 << 553 Sorry, that domain isn't in my list of allowed rcpthosts.<EOL>
09/05/20 00:25:02 ** Disconnecting from smtpout.secureserver.net:25
09/05/20 00:25:02 ** Disconnected.
09/05/20 00:25:02 ** Disconnected.
09/05/20 00:25:02 ** Sorry, that domain isn't in my list of allowed rcpthosts.<EOL>


Thank you.
gshiga
 
Posts: 8
Joined: 11. May 2009 23:16

Re: Sendmail problem w/ PHP Form submit

Postby Wiedmann » 20. May 2009 09:54

I guess "info@example.com" is just for us and not what you are really using? And you are still using "POP3".

Aside from that, it looks good for me. Maybe you want ask your isp what's the problem?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 137 guests