Page 1 of 1

PHP form not working... Help please!

Posted: Tue Oct 27, 2009 1:12 am
by becfaye2000
Hi
I have a HTML form, powered by PHP on a website, however I am having problems with it as I am new to PHP, and for some reason the form response is not being received.

The php code I am using is:

Code: Select all

<?php 
$errors = '';
$myemail = 'email@domain.com';//<-----Put Your email address here.
if(empty($_POST['FirstName'])  || 
   empty($_POST['LastName']) || 
   empty($_POST['Phone']) || 
   empty($_POST['Email']) ||    
   empty($_POST['Enquiry']))
{
    $errors .= "\n Error: all fields are required";
}
 
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email']; 
$Enquiry = $_POST['Enquiry']; 
 
if (!eregi(
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 
$Email))
{
    $errors .= "\n Error: Invalid email address";
}
 
if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Website Enquiry";
    $email_body = "Website Enquiry ".
    " Here are the details:\n Name: $FirstName \n $LastName \n Day Phone: $Phone \n Email: $Email \n Enquiry \n $Enquiry"; 
    
    $headers = "From: $myemail"; 
    $headers .= "Reply-To: $Email";
    
    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: http://www.earnosethroat.com.au/success.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Error</title>
</head>
 
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
 
 
</body>
</html>
The form is available at: http://www.earnosethroat.com.au/contactus_php.html

If anyone can help me work out why I am not receiving it, would be much appreciated.

Thanks
Bec

Re: PHP form not working... Help please!

Posted: Tue Oct 27, 2009 1:41 am
by MatthewNicoll
Have you put your email in the part:

$myemail = 'email@domain.com';//<-----Put Your email address here.

Might be something you've overlooked..

Re: PHP form not working... Help please!

Posted: Tue Oct 27, 2009 7:16 pm
by becfaye2000
Sorry, yes I have entered my correct email address in.
I just wasn't too keen on showing my real email address due to spam.

Any other ideas?

Re: PHP form not working... Help please!

Posted: Wed Oct 28, 2009 4:50 am
by madhurima
Localhost doesn't support sending mails.So, try using FTP.