PDA

View Full Version : PHP html php form



jerome.chevreau
November 26th, 2008, 02:57 AM
Hi everyone,

I have a simple form that i am testing. i use a php file to do the validation check and sending the form. But the only prob is that most of my mails tests are going to my junk. I send it to my gmail (do you think it can be a prob). Anyway, im still trying to fix it but i dont see any prob witht the php. Below is my code, the hmtl page and the php. Please if someone can hellp me it would be great.... i am going nuts;(, lol.

Thanks a lot for any help.



<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>XHTML Form Test 0001</title>

</head>

<body>

<?php
//isset --- determines wether a variable is set
if (!isset($_POST['submitForm'])) {
?>

<form action="form.php" method="POST">

<table>

<tr>

<td>Name:</td>

<td><input type="text" name="name"></td>

</tr>

<tr>

<td>Email:</td>

<td><input type="text" name="email"></td>

</tr>

<tr>

<td>Message:</td>

<td><textarea name="mesg"></textarea></td>

</tr>

<tr>

<td><input type="submit" name="SubmitForm" value="Send"></td>

</tr>

<form>

<?php
} else {
echo "Form submitted!";
}
?>

</body>

</html>


THE PHP FOLLOWS BELOW:




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>HTML PHP FORM TESTING</title>
</head>
<body style="font-family: Arial">

<?php
// Function to display form
function showForm($errorName=false,$errorEmail=false,$error Mesg=false){

if ($errorName) $errorTextName = "Please enter your name!";
if ($errorEmail) $errorTextEmail = "Please enter a valid email address!";
if ($errorMesg) $errorTextMesg = "Please leave a longer message!";

echo '<form action="form.php" method="POST"><table>';

// Display name field an error if needed
echo '<tr><td>Name:</td><td><input type="text" name="name"></td></tr>';
if ($errorName) echo "<tr><td colspan='2'>$errorTextName</td></tr>";

// Display email field an error if needed
echo '<tr><td>Email:</td><td><input type="text" name="email"></td></tr>';
if ($errorEmail) echo "<tr><td colspan='2'>$errorTextName</td></tr>";

// Display message field an error if needed
echo '<tr><td>Message:</td><td><textarea name="mesg"></textarea></td></tr>';
if ($errorMesg) echo "<tr><td colspan='2'>$errorTextMesg</td></tr>";

echo '<tr><td><input type="submit" name="SubmitForm" value="Send"></td></tr>';
echo '<form>';
}

if (!isset($_POST['SubmitForm'])) {
showForm();
} else {

//Init error variables
$errorName = false;
$errorEmail = false;
$errorMesg = false;

$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$mesg = isset($_POST['mesg']) ? trim($_POST['mesg']) : '';

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) $errorEmail = true;

if (strlen($name)<3) $errorName = true;

if (strlen($mesg)<10) $errorMesg = true;

// Display the form again as there was an error

if ($errorName || $errorEmail || $errorMesg) {
//call function showForm parsing the variables which has beenset to TRUE
showForm($errorName,$errorEmail,$errorMesg);

} else {

echo 'Submission was success!';

$mailto = "jerome.chevreau@gmail.com";
$subject = "Order Form Test";

$message = "Name: " . $name;
$message .= "\nEmail: " . $email;
$message .= "\n\nMessage: " . $mesg;

$headers = "From: $email";
$headers .= "\nReply-To: $email";

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

}

}

?>
</body>
</html>

simplistik
November 26th, 2008, 06:35 AM
the server that you're sending from must be flagged as a spamish server.
a) make sure you're sending proper headers, title's and relevant body copy (trying using lorem ipsum to test with) and
b) set up a SPF, you can use http://old.openspf.org/wizard.html

djheru
December 2nd, 2008, 04:53 PM
One thing is that you are forging the from header. You should use a system email address that actually exists to send the email. When the recieving server sees an email that says it's from joe@hotmail.com, but it is actually coming from you@yourdomain.com, that is a big red flag. You should also include other headers, such as MIME version, content type, a message id, and x-mailer.

If you want better success sending emails, you should look on a site like phpclasses.org for an email class that you can call in a similar method to the php built in mail() function