I have coded a web site from scratch with XHTML, using Windows XP Pro, and this includes a contact form in PHP. The web site is in a XAMPP folder on the C drive and being run under localhost on my computer at home.
I want to test the form by sending an email test message from it to my live email address. I have tried this by changing the SMTP = localhost
in the PHP .ini
file to my ISP server address, activating the line,
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
and adding a semicolon to the beginning of the line below,
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
I have placed my live email address in the contact form code like so:
<?php
//send email
if(mail('my@emailaddress.net','Contact
form',$msg, 'From:postmaster@localhost')) {
?>
Then I tried another way by placing my email address under the if(POST) function
instead:
<?php
if($_POST) {
$fName = $_POST['fName'];
$fEmail = $_POST['fEmail'];
$fComments = $_POST['fComments'];
$fCaptcha = $_POST['fCaptcha'];
$random_string = $_POST['random_string'];
$to = "myemailaddress@myisp.net";
?>
And changed the mail function lower down in the script accordingly:
<?php
//send email
mail($to, $fName, $fEmail, $fComments);
if(mail($to,'Contact form',$msg, 'From:postmaster@localhost')) {
header("Location: ../email-thankyou.htm");
?>
When I clicked on the submit button, it generated an error page from my ISP server the first time, and from the Firefox browser during later attempts, so something is happening, but in looking at my live email account there is no sign of my message arriving.
I also found that the form itself disappeared and I was left with just the background colour of the page, when clicking on the submit button when I tried the second method.
I have searched through Stack Overflow for similar queries, and tried a few suggestions without success.
I am using XAMPP version 3.1.0.3.1.0. Although I am conversant with XHTML coding, I am a complete novice with regards to PHP programming, as this project using PHP is my first effort to get to grips with it, and would really appreciate any help and advice given, particularly as to writing the mail($to, and if(mail($to, out
correctly.
I have now found the answer to this question by downloading and installing smtp4dev 2009 on my C drive. With this little program in conjunction with XAMPP, I can now test my contact form and it receives the messages successfully. The only other thing I needed to to was to configure the XAMPP php ini file as follows:
[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"
As far as the earlier problem of the form disappearing when clicking on the Send button, is concerned - part of the script was in the wrong place and after some trial and error in positioning it, this problem was solved.