Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   What's wrong with my code? (http://www.go4expert.com/forums/whats-wrong-code-t12377/)

Steel9561 23Jul2008 23:37

What's wrong with my code?
 
The following code is suppose to check whether the user filled out the fields on a form. Each field is called fmail1, fmail2 and fmail3 and they are textboxes on the form. This script supposedly checks whether the user has entered only one email, two or three emails on the text boxes and based on that it sends an email to email address in $emailto. So if 3 emails are entered, 3 emails are sent to myaddress@test.com each containing a different email address. This code doesn't work! I have to assume something is wrong, please help me find what's wrong with the following code:

// Email address for copies to be sent to - change to suit
$emailto = "myaddress@test.com";

// Notification email subject text for copies
$esubject = "Recommendation form submission friend 1";
$esubjecttwo = "Recommendation form submission friend 2";
$esubjectthree = "Recommendation form submission friend 3";

// Email body text for notifications
$emailtextone = "
$_POST[name] has used your recommendation form using an email address of $_POST[email]

The people the recommendation has been submitted to are:

$_POST[fmail1]

Agreed to the contest's rules and conditions: Yes

The page recommended:

$_POST[refurl]

";


// Email body text for notifications
$emailtexttwo = "
$_POST[name] has used your recommendation form using an email address of $_POST[email]

The people the recommendation has been submitted to are:

$_POST[fmail2]

Agreed to the contest's rules and conditions: Yes

The page recommended:

$_POST[refurl]

";

// Email body text for notifications
$emailtextthree = "
$_POST[name] has used your recommendation form using an email address of $_POST[email]

The people the recommendation has been submitted to are:

$_POST[fmail3]

Agreed to the contest's rules and conditions: Yes

The page recommended:

Code:

$_POST[refurl]

";


if ($_POST['fmail1'] !="") && ($_POST['fmail2'] !="") && ($_POST['fmail3'] !="") {

# This function sends the email to you

mail("$emailto", $esubject, $emailtextone, "From: $_POST[email]");
mail("$emailto", $esubjecttwo,$emailtexttwo, "From: $_POST[email]");
mail("$emailto", $esubjectthree, $emailtextthree, "From: $_POST[email]");

} elseif ($_POST['fmail1'] !="") && ($_POST['fmail2'] !="") && ($_POST['fmail3'] =="") {

# This function sends the email to you

mail("$emailto", $esubject, $emailtextone, "From: $_POST[email]");
mail("$emailto", $esubjecttwo,$emailtexttwo, "From: $_POST[email]");

} elseif ($_POST['fmail1'] !="") && ($_POST['fmail2'] =="") && ($_POST['fmail3'] =="") {

# This function sends the email to you

mail("$emailto", $esubject, $emailtextone, "From: $_POST[email]");

} elseif ($_POST['fmail1'] !="") && ($_POST['fmail2'] =="") && ($_POST['fmail3'] !="") {

# This function sends the email to you

mail("$emailto", $esubject, $emailtextone, "From: $_POST[email]");
mail("$emailto", $esubjectthree, $emailtextthree, "From: $_POST[email]");

} else {
 echo "";
}



All times are GMT +5.5. The time now is 11:04.