PHP form not working... Help please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
becfaye2000
Forum Newbie
Posts: 2
Joined: Tue Oct 27, 2009 1:08 am

PHP form not working... Help please!

Post 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
MatthewNicoll
Forum Newbie
Posts: 4
Joined: Mon Oct 26, 2009 9:11 pm

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

Post 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..
becfaye2000
Forum Newbie
Posts: 2
Joined: Tue Oct 27, 2009 1:08 am

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

Post 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?
madhurima
Forum Newbie
Posts: 15
Joined: Thu Mar 12, 2009 4:55 am

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

Post by madhurima »

Localhost doesn't support sending mails.So, try using FTP.
Post Reply