...

View Full Version : Help with contact form.



vwhatizthiz
07-24-2012, 07:34 PM
Hi everyone, I'm trying to create a contact form with a simple validation question (what is 2+2) because I've been getting a lot of spam e-mails. I want it to just display a popup box on the same page saying that the message was either sent successfully, not sent, or they got the question wrong.

Unfortunately I keep getting errors with it and I can't seem to figure it out. Any help?

HTML:



<form id="contactus" method="post" action="contactengine.php">
<p>contact</p>
<label for="Name">name:</label>
<input type="text" name="name" id="name" placeholder="e.g., John Doe" />

<label for="Email">e-mail:</label>

<input type="text" name="email" id="email" placeholder="johndoe@example.com"/>

<label>what is 2+2? (anti-spam)</label>
<input name="spam" placeholder="">

<label for="Message">message:</label>
<textarea name="message" id="message" placeholder="Send us any questions, comments, or ideas you may have!"></textarea>

<input type="submit" name="submit" value="Submit" id="submit" />
</form>


PHP:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = '******';
$to = '********';
$subject = 'Message from a site visitor.';
$body = "From: $name\nE-Mail: $email\nMessage:\n $message"; /
if ($_POST['submit'] && $spam === '4') {

if (mail ($email, $subject, $body)) {
?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.php';
</script>
<?php
} else { //end of PHP, start of JS ?>
<script language="javascript" type="text/javascript">
alert('Something went wrong! Please go back and try again.');
window.location = 'index.php';
</script>
<?php //end of JS, start of PHP
}
} else if ($_POST['submit'] && $spam != '4') {
?>
<script language="javascript" type="text/javascript">
alert('You answered the anti-spam question wrong! Please go back and try again.');
window.location = 'index.php';
</script>
<?php //end of JS start of PHP
}
?>

hackarchives
07-24-2012, 08:00 PM
Unfortunately I keep getting errors with it and I can't seem to figure it out. Any help?


What errors are you getting?

vwhatizthiz
07-24-2012, 08:20 PM
What errors are you getting?

I get the error that I answered the anti-spam question incorrectly, even though I put 4.

Keleth
07-24-2012, 09:05 PM
If that's your whole code, I don't see where $spam is being set. That seems like the issue.

Arcticwarrio
07-24-2012, 09:57 PM
//add
$spam = $_POST['spam'];

vwhatizthiz
07-25-2012, 05:07 AM
Ok, so currently I have this PHP:


<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$spam = $_POST['spam'];
$from = 'edited out';
$to = 'edited out';
$subject = 'Message from a site visitor.';
$body = "From: $name\nE-Mail: $email\nMessage:\n $message";
if ($_POST['submit'] && $spam === '4') {

if (mail ($name, $email, $message)) {
?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.php';
</script>
<?php
} else { //end of PHP, start of JS ?>
<script language="javascript" type="text/javascript">
alert('Something went wrong! Please go back and try again.');
window.location = 'index.php';
</script>
<?php //end of JS, start of PHP
}
} else if ($_POST['submit'] && $spam != '4') {
?>
<script language="javascript" type="text/javascript">
alert('You answered the anti-spam question wrong! Please go back and try again.');
window.location = 'index.php';
</script>
<?php //end of JS start of PHP
}
?>

But for some reason I'm not getting the e-mails. I checked the address it's being sent to and I even checked the spam folder, but no dice. In fact, the e-mail was actually sent to the 'from' email address. Help?

Is it something with my HTML?


<form id="contactus" method="post" action="contact.php">
<p>contact</p>
<label for="Name">name:</label>
<input type="text" name="name" id="name" placeholder="e.g., John Doe" />

<label for="Email">e-mail:</label>

<input type="text" name="email" id="email" placeholder="johndoe@example.com"/>

<label>what is 2+2? (anti-spam)</label>
<input name="spam" placeholder="">

<label for="Message">message:</label>
<textarea name="message" id="message" placeholder="Send us any questions, comments, or ideas you may have!"></textarea>

<input type="submit" name="submit" value="Submit" id="submit" />
</form>

Arcticwarrio
07-25-2012, 09:25 AM
mail is:



$to = $_POST['email'];
$subject = "Test mail";
$message = "here";
$from = "abc.sample@gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);


see this post:

http://www.codingforums.com/showpost.php?p=1254269&postcount=10



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum