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!
Genji