What's wrong with my code?

Discussion in 'PHP' started by Steel9561, Jul 23, 2008.

  1. Steel9561

    Steel9561 New Member

    Joined:
    Apr 26, 2008
    Messages:
    14
    Likes Received:
    1
    Trophy Points:
    0
    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

    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 "";
    }[/CODE]
     
    Last edited by a moderator: Jul 24, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice