Why doesn't my Contact Form work?

Hi,

I’ve been having serious difficulty trying to get my contact form to work. I am very inexperienced with PHP, so I’d imagine this is a simple question.

I would greatly appreciate any help. Thanks in advance.

URL: http://www.austinlindsay.com/contact.html

Here’s the code:

contact.html:

<div id=“contact_form”><form method=“POST” action=“contact.php”>
Fields marked (*) are required

<p>Email From:* <br>
<input type=“text” name=“EmailFrom”>
<p>Subject: <br>
<input type=“text” name=“Subject”>
<p>Name:<br>
<input type=“text” name=“Name”>
<p>YourMessage:<br>
<textarea name=“YourMessage”></textarea>
<p><input type=“submit” name=“submit” value=“Submit”>
</form>
<p>

<!-- Contact Form credit link -->
Created by <a target="_blank"
href=“http://www.tele-pro.co.uk/scripts/contact_form/”>Contact
Form Generator</a></div>

contact.php:

<?php
// Website Contact Form Generator
// http://www.tele-pro.co.uk/scripts/contact_form/
// This script is free to use as long as you
// retain the credit link

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST[‘EmailFrom’]));
$EmailTo = "jlindsay101@aol.com";
$Subject = Trim(stripslashes($_POST[‘Subject’]));
$Name = Trim(stripslashes($_POST[‘Name’]));
$YourMessage = Trim(stripslashes($_POST[‘YourMessage’]));

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print “<meta http-equiv=“refresh” content=“0;URL=error.htm”>”;
exit;
}

// prepare email body text
$Body = “”;
$Body .= "Name: ";
$Body .= $Name;
$Body .= “
”;
$Body .= "YourMessage: ";
$Body .= $YourMessage;
$Body .= “
”;

// send email
$success = mail($EmailTo, $Subject, $Body, “From: <$EmailFrom>”);

// redirect to success page
if ($success){
print “<meta http-equiv=“refresh” content=“0;URL=ok.htm”>”;
}
else{
print “<meta http-equiv=“refresh” content=“0;URL=error.htm”>”;
}
?>

just a wild guess here but i believe it is because ur giving the ($Body .) to many variables, u might want to try to bracket them, EG.
$Body = ("",“Name: “,$Name,”
”, "YourMessage: ",$YourMessage, “
”);
and i would possibly check the variables you have given it,it doesnt make sense to me.

but considering this looks kinda like a email couldnt you put something like

$body = “<body>(something to insert text here)</body>”

Hey, thanks for your response.

I don’t understand any of the code. I just found a website that generated the code for me.

Instead of using the above use this one ->http://www.000webhost.com/forum/web-programming/18460-one-php-contact-form-works-another-does-not-can-you-tell-me-why.html#post90641

What´s the problem with the script above anyway? Any error message ?

I’m having more luck with this one - the form submits but I do not receive the email, despite changing the email to: $my_email = "jlindsay101@aol.com";

Any idea where I’m going wrong?

Also, is there a way to remove the box around the text fields?

Thanks.

not sure what you mean with border around the text fields. If you mean the background behind the text fields just change

<table border="0" style="background:#ececec" cellspacing="5">

to

<table border="0" cellspacing="5">

Did you check your spam folder and/or made sure that mail from 000webhost.com servers isn´t blocked?

Thanks, the background thing worked.

But yeah, I’ve checked my spam folder and I know that my mail from 000webhost isn’t blocked because I receive a notification when a forum post has been made.

Is it definitely an issue with email accounts, or could it be something else?

have you got an alternative email account that you could try with? I know it works as i used googlemail.com and outlaw-forum.info when testing that script, as well as the mail address of my free hosting account here. Everything worked just fine…but then you have aol hehe :slight_smile:

I know. It’s not the best email provider! But I’ve tried a different email address and it still doesn’t work.

But it could be something else, maybe? I’ve placed it in a div tag, if that matters?

not really, placing it in a div tag shouldn´t matter (as long as you put the HTML part in a div container, not the php code in the contact.php file. Can you post the entire contents of your contact.php file please?

Of course. Here it is. Thanks…

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8” />
<title>Untitled Document</title>
</head>

<body>

<?php

error_reporting(E_ALL ^ E_NOTICE);

$my_email = "jlindsay@aol.com";
$from_email = “”;
$continue = “/contact.html”;

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Validate email field.

if(isset($_REQUEST[‘email’]) && !empty($_REQUEST[‘email’]))
{

$_REQUEST[‘email’] = trim($_REQUEST[‘email’]);

if(substr_count($_REQUEST[‘email’],"@") != 1 || stristr($_REQUEST[‘email’]," “)){$errors[] = “Email address is invalid”;}else{$exploded_email = explode(”@",$_REQUEST[‘email’]);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = “Email address is invalid”;}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = “Email address is invalid”;}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = “Email address is invalid”;}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match(’/^[a-z0-9-]+$/i’,$value)){$errors[] = “Email address is invalid”; break;}}}}}}

}

// Check referrer is from same site.

if(!(isset($_SERVER[‘HTTP_REFERER’]) && !empty($_SERVER[‘HTTP_REFERER’]) && stristr($_SERVER[‘HTTP_REFERER’],$_SERVER[‘HTTP_HOST’]))){$errors[] = “You must enable referrer logging to use the form”;}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = “You cannot send a blank form”;}

unset($set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print “$value<br>”;} exit;}

if(!defined(“PHP_EOL”)){define(“PHP_EOL”, strtoupper(substr(PHP_OS,0,3) == “WIN”) ? “
” : “
”);}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," “,ucfirst($key)).”: “.build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).”, “;}}}}return rtrim($message_output,”, ");}

$message = build_message($_REQUEST);

$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL.“Thank you for using our contact form.”;

$message = stripslashes($message);

$subject = “Contact Form”;

$subject = stripslashes($subject);

if($from_email)
{

$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST[‘email’];

}
else
{

$from_name = “”;

if(isset($_REQUEST[‘name’]) && !empty($_REQUEST[‘name’])){$from_name = stripslashes($_REQUEST[‘name’]);}

$headers = “From: {$from_name} <{$_REQUEST[‘email’]}>”;

}

mail($my_email,$subject,$message,$headers);

?>

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>

<head>
<title>Just some title</title>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”>
</head>

<body bgcolor="#333" text="#FFF">

<div>
<center>
<b>Thank you <?php if(isset($_REQUEST[‘name’])){print stripslashes($_REQUEST[‘name’]);} ?></b>
<br>Your message has been sent
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>

</center>
</div>

</body>
</html>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

Where does that come from? if it´s in the contact.php file remove it

Okay, have done. I guess that means I should take out the closing head and body tags?

I tried but I’m still not getting anything, though.

Can you do a quick test please?
Fill out and submit the form at http://just2test.freeiz.com/contact.html
I set it up with your email address now, tested it with mine a minute ago and worked perfectly. let´s see if you get any mail when submitting the form

I haven’t got anything - so it’s obviously a problem with my email address, right?

Or could it be that I don’t have sufficient privileges on 000webhost?

I really appreciate your time. Thanks.

it´s not about privileges or something, maybe it´s down to aol having blacklisted 000webhost (just a thought, there can be many other reasons). The best thing to test if it´s really down to aol is to use an alternative email address and see if you get the mail there

I tried it with a yahoo email address and that didn’t work, either.

Other things to note:

I’ve called the pages: contact.php and contact.html

The php file is in the same directory as the html

That´s fine, else it wouldn´t work unless you would have specified the path to the .php file hehe.

Erm…if even Yahoo doesn´t work it´s really weird. Just checked the server ip against the most commom spam/rbl blacklists but couldn´t find any entry at all.
Starting to run out of ideas hehe. Can you please tell me which server you are on?

I don’t understand, sorry.

My domain was bought from name.com but I don’t think that’s what you meant.

How can I find out which server I’m on?

log into your 000webhost member area, on the right side there should be something like server**.000webhost.com (** being two numbers). That´s the server name i need to cross-check on the spam blacklists