simple php form help

ruyav

Active Member
Joined
Feb 11, 2012
Messages
38
Reaction score
0
Hi

Im working on a really simple php form but i cant get it to send me the email :/ Can someone please look at this code and tell me whats wrong?

html on contact.html

Code:
<form id="form2" method="post" action="mailer.php">
	                                <fieldset>
	                                    <input id="con_name" type="text" name="name" value="Name:" alt=""/><br />
	                                    <input id="con_email" type="text" name="email" value="E-mail:" alt=""/><br />
	                                    <textarea id="con_mess" name="message" cols="0" rows="0">Message:</textarea><br />
	                                    <input type="submit" id="contact-submit" value="Send"/>
	                                    <input type="button" id="contact-clear" value="Reset"/>
	                                </fieldset>
	                            </form>

php in mailer.php

Code:
<?php
if(isset($_POST['send'])) {

 $to = '[email protected]'; 
	
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "blarg!";

}
?>
 
Change


Code:
if(isset($_POST['send'])) {

to
Code:
if(isset($_POST['contact-submit'])) {

and it will work.
$_POST/GET.... you should look for the variable here, not the value.

The value of $_POST['contact-submit'] is "Send".
 
You're also missing a From so maybe your SMTP server is ditching it:

Code:
mail($to, $subject, $body, "From: ".$email_field."\n");

and even then, it may fail so:

Code:
mail($to, $subject, $body, "From: ".$email_field."\n", "-f ".$email_field);

which also may not work, if foreign email is prohibited. In this case, use an approved from instead of $email_field
 
Don't forget to supress your warnings with an @

eg: @mail($

even better, do something like

$res=@mail($to,..

if($res==NULL) { echo "Failed"; }
 
Change


Code:
if(isset($_POST['send'])) {

to
Code:
if(isset($_POST['contact-submit'])) {

and it will work.
$_POST/GET.... you should look for the variable here, not the value.

The value of $_POST['contact-submit'] is "Send".

Did not work :/
 
<input type="submit" id="contact-submit" name="send" value="Send"/>

Put the name attribute

and use

if(isset($_POST['send'])) {
 
Top
Sign up to the MyBroadband newsletter
X