What is wrong specifically?
I have made a very simple email form, and I'm having trouble with it emailing me the results. The url for the test form that I made is at http://universalcarpet.org/form.html
Can someone look at these codes and see what I'm doing wrong please?
here is the PHP code titled inquire.php
<?php
/* Subject and Email Variables */
$emailsubject = 'Quote Form Inquire';
$webMaster = 'john@universalcarpet.org';
/* Gathering Data*/
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$zipField = $_POST['zip'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Zip Code: $zip <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailsubject, $body, $headers);
/* Results rendered as HTML*/
$theResults = <<<EOD
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<h2 align="center">Thank you for your request, we will contact you very soon! </h2>
</body>
</html>
EOD;
echo "$theResults";
?>
Here is the html code for the form
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="225" border="0" cellspacing="5" cellpadding="5">
<tr>
<td bgcolor="#336699"><form action="inquire.php" method="post" name="form">
<p>Name<br />
<input name="name" type="text" id="name" />
</p>
<p>Email<br />
<input name="email" type="text" id="email" />
</p>
<p>Phone<br />
<input name="phone" type="text" id="phone" />
</p>
<p>Zip Code<br />
<input name="zip" type="text" id="zip" />
</p>
<p>
<input name="Submit" type="submit" id="submit" value="Submit" />
<input name="Submit" type="reset" id="Submit" value="Reset" />
</p>
</form></td>
</tr>
</table>
</body>
</html>
Thank you in advance for any help you can give me!![]()
What is wrong specifically?
Nick
"Beware of bugs in the above code; I have only proved it correct, not tried it."
- Donald E. Knuth.
Is $success returning true or false. Try a try/catch statement. Something like:
PHP Code:<?php
// ..
try
{
$success = mail($webMaster, $emailsubject, $body, $headers);
echo $success;
}
catch (Exception $e)
echo "There was a problem: " . $e->getMessage();
Nick
"Beware of bugs in the above code; I have only proved it correct, not tried it."
- Donald E. Knuth.
Could you not use a free email form for this? I know what a pain it can be but some of the free forms like Jotform and Kontact are pretty customisable. I have signed up for new accounts for each new website using the forms. You can technically sign up for several accounts and use several identical forms on different pages of the site - this gets around the issue of reaching the quota for receiving messages free. Otherwise you have to pay to receive the emails.
Where do I put this code? I tried to put it at top of the php page, and by the $success = mail($webMaster, $emailsubject, $body, $headers); area, but when I published it, it said internal error 500. Do I make this a page by itself and attach that page to me html form? I'm new at this stuff, sorry, but I have limited knowledge.. lol
Thanks,
John
You put the try right above the $success variable, then replace $success with what's in the try.
Nick
"Beware of bugs in the above code; I have only proved it correct, not tried it."
- Donald E. Knuth.
Darren,
Ya I've done that a bunch of times, but I'd really like to be able to do it myself... but I appreciate your help ;-)
Here is where I put the code.. I have it in bold... I still got the same error on this.
<?php
/* Subject and Email Variables */
$emailsubject = 'Quote Form Inquire';
$webMaster = 'john@universalcarpet.org';
/* Gathering Data*/
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$zipField = $_POST['zip'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Zip Code: $zip <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
try
{
$success = mail($webMaster, $emailsubject, $body, $headers);
echo $success;
}
catch (Exception $e)
echo "There was a problem: " . $e->getMessage();
/* Results rendered as HTML*/
$theResults = <<<EOD
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<h2 align="center">Thank you for your request, we will contact you very soon! </h2>
</body>
</html>
EOD;
echo "$theResults";
?>
I had to change my php to a older version on my host account.. it now gave me a code on where I put the variable above.. here is the message:
Parse error: syntax error, unexpected '{' in /home/www/universalcarpet.org/inquire.php on line 27
on line 27 it is this { right after the word try.
I wrote in a try without braces.
PHP Code:try
{
// $success goes here
}
catch (Exception $e)
{
// Catch goes here
}
Nick
"Beware of bugs in the above code; I have only proved it correct, not tried it."
- Donald E. Knuth.
I got the same message.. I'm sure I'm doing something wrong.. I don't know anything about php, so unless I can copy and paste in a code, I'm lost! lol..
this is what I typed in..
try
{
$success = mail($webMaster, $emailsubject, $body, $headers);
echo $success;
}
catch (Exception $e)
{
echo "There was a problem: " . $e->getMessage();
}
it's still telling me that the { is my problem.. So I'm lost. But I thank you for your time sir.. You have to understand I'm like a total beginner at this so its like your talking to a 3 yr old.. lol
Thanks again
I found out that it is working fine in Mozilla Firefox, but it's not sending the email in Chrome. So it must not be the php, but my browser preferences i guess.. thanks guys!
I don't see how it could be working fine when obviously it is not going to collect anything:
See for instance $name and $nameField.. They should be the same./* Gathering Data*/
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$zipField = $_POST['zip'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Zip Code: $zip <br>
EOD;
As for actually sending the email, some webhosting providers change the order of arguments of the mail function in an attempt to prevent automated hackers from easily using their servers to send spam via pre-made scripts. But in that case they make it clear in their FAQ for their customers.
Start writing the best reviews, building backlinks (SEO) and earning good money.
Want traffic? Advertise on my sites today: She Told Me & Best Reviewer : 250,000+ UV / Month
Thank you for all your help! ;-)