View Full Version : PHP Contact Form
dholi
December 20th, 2009, 09:31 PM
Hi,
I've used the php contact form tutorial on this website, replaced it with my email address and uploaded it to my server.
http://www.kirupa.com/web/php_contact_form2.htm (http://www.kirupa.com/forum/../web/php_contact_form2.htm)
Once I click Submit I don't get any errors or anything. and it takes me to the thank you page.
When I check my email theres no email sent. :diss:
Why could this be?
ichsie2036
December 21st, 2009, 12:22 AM
Did you mean no email sent of no email received? The email is sent from the server by mail() function not your email. So you didn't receive the email sent from the contact form? Did you check the spam folder?
NeoDreamer
December 21st, 2009, 02:40 AM
You need to check if the mail function actually worked.
<?php
if(isset($_POST['submit'])) {
$to = "you@you.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
if (mail($to, $subject, $body)) {
echo "Data has been submitted to $to!";
}
else {
echo 'The mail function failed';
}
} else {
echo 'nothing was submitted yet';
}
?>
vishu
December 21st, 2009, 10:16 AM
you may also need to specify the $header parameter in the mail function, though it's least likely to be causing you this problem...:S
dholi
December 21st, 2009, 10:17 AM
Thanks for the reply everyone.
"NeoDreamer" I tried the code that you gave, and tested it. It came up with
The mail function failed.
What does this mean?
dholi
December 21st, 2009, 10:20 AM
you may also need to specify the $header parameter in the mail function, though it's least likely to be causing you this problem...:S
I've tried so many forms that I've found online, but haven't got even one of them to work.. :sad2:
Does anyone have a simple working form I can try?
simplistik
December 21st, 2009, 10:55 AM
Thanks for the reply everyone.
"NeoDreamer" I tried the code that you gave, and tested it. It came up with
The mail function failed.
What does this mean?
According to the script he provided for you it means that the mail function failed. You need to check to make sure mail() is available on your server.
dholi
December 21st, 2009, 05:13 PM
I tried this very simple php code, and it worked.
So I presume this test indicates my server mail() function is available...and it's just the php coding thats wrong?
<?php
$to = "email@example.com";
$subject = "Test Mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
NeoDreamer
December 22nd, 2009, 02:42 AM
The code that you posted will always echo "mail sent" no matter if the mail function failed or not. The mail function returns a boolean. You are not checking if it returns false, meaning it failed.
I believe you don't have a mail server.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.