/    Sign up×
Community /Pin to ProfileBookmark

can’t received form info

HI

I am very new at learning php, but i did this form tutorail a few days ago. The form appears to be working properly but i do not get any e-mails. The mail function is there and i do not get any errors when i click submit, just no e-mails. Can someone please point out where the error is. Thank you in advance.

<?php
// 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=”SubmitForm” value=”Send”></td></tr>’;

echo ‘<form>’;

}

if(isset($_POST[‘submit’])) {
$to = “[email protected]”;
mail($to, $subject, $body);

} 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 ‘Submission was success!’;
echo “<meta http-equiv=’refresh’ content=’0;url=http://www.iheartvacation.com’>”;
}
}

?>

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@toenailsinSep 08.2008 — your script is searching for a post field with the name of 'submit'. replace that with a valid field name and you should be flying

eg:

$_POST['FieldName']

<input name="FieldName" />
Copy linkTweet thisAlerts:
@khujo56authorSep 08.2008 — Hi

This might sound a bit dumb and i apologize but is that where i put my e-mail address.
Copy linkTweet thisAlerts:
@khujo56authorSep 09.2008 — Hi

I still get no e-mails after i added what was missing. I am in desperate need of some help to correct this error. I have listed the script below. Next time i will just pay someone to write the script.

<?php

$to = "[email protected]";

$name = $_POST['name'] ;

$email = $_
POST['email'] ;




// 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="SubmitForm" value="Send"></td></tr>';

echo '<form>';

}





if(isset($_POST['submit'])) {
mail( "$email", "Sign Up",
$message, "$to, $subject, $body" );


} 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 'Submission was success!';
echo "<meta http-equiv='refresh' content='0;url=http://www.iheartvacation.com'>";
}


}

?>
Copy linkTweet thisAlerts:
@toenailsinSep 09.2008 — I was meaning that these two fields don't match up. Change one to match the other.

[CODE]echo '<tr><td><input type="submit" name="[COLOR="Red"]SubmitForm[/COLOR]" value="Send"></td></tr>';

///////////////

if(isset($_POST['[COLOR="Red"]submit[/COLOR]'])) {
$to = "[email protected]";
mail($to, $subject, $body);
} else {[/CODE]


also, its alot easier to read the code when they're in &#91;CODE]&#91;/CODE] tags
Copy linkTweet thisAlerts:
@khujo56authorSep 09.2008 — Hi

I tried what you suggested but unfortunately no e-mails. This is a tricky one?
×

Success!

Help @khujo56 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...