PDA

View Full Version : PHP form emails not received



khujo56
September 11th, 2008, 11:45 PM
HI Guys

I followed this tutorial on how to create a php form. The problem i have is that when i fill in the info and click send, everything appears well but the info is not being sent to the assigned e-mail. I'm not sure what is wrong. Hopefully someone can catch error. Your help is greatly appreciated.



<?php
error_reporting(E_ALL);

// Function to display form


function showForm($errorName=false,$errorEmail=false){

if ($errorName) $errorTextName = "Please enter your name!";

if ($errorEmail) $errorTextEmail = "Please enter a valid email address!";


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'>$errorTextEmail</td></tr>";

echo '<tr><td><input type=submit name="send" value="Submit"></td></tr>';

echo '<form>';

}

if ( isset($_POST["Submit"]) ) {

$email = $_POST['email'];
$subject = 'your subject here';
$message = 'your message';
$reply_to = 'jnr1975@hotmail.com';
$from = 'you@yourdomain.com';

mail( $email, $subject, $message, "From: {$from}\r\nReply-to: {$reply_to}" );


} else {

//Init error variables

$errorName = false;

$errorEmail = false;



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

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



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;




// Display the form again as there was an error

if ($errorName || $errorEmail) {

showForm($errorName,$errorEmail);

} else {


echo 'Thamk you for signing up!';
echo "<meta http-equiv='refresh' content='0;url=http://www.iheartvacation.com'>";
}


}

?>

tfg
September 12th, 2008, 07:05 AM
i'm glad to see you've got error reporting turned on :) that means you'd already know if there were script errors

if the php form says all is well but the emails aren't coming through it would suggest to me that the mail server is relaying the messages through. check with your hosting provider if there are any special requirements that must be fulfilled before they allow the messages out.

i have sites hosted with fasthosts who have specific criteria that must be met otherwise they will purge the messages from the outgoing server in an attempt to reduce the spam that passes through their systems.