PHP Error

Discussion in 'PHP' started by NeighborNicks, Jul 19, 2009.

  1. #1
    Hey Guys,

    I am finishing a contact form and I get this error when I go to submit:

    Parse error: syntax error, unexpected ':' in /var/www/vhosts/sparksolutions.net/httpdocs/contact.php on line 69

    Here is the entire code for the form on www.sparksolutions.net/support.html

    <?php

    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "Support@SparkSolutions.net";
    $Subject = "Support Form Request";
    $Name = Trim(stripslashes($_POST['Name']));
    $Telephone = Trim(stripslashes($_POST['Telephone']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Company = Trim(stripslashes($_POST['Company']));
    $Website = Trim(stripslashes($_POST['Website']));
    $WebDesignandDevelopment = Trim(stripslashes($_POST['WebDesignandDevelopment']));
    $Ecommerce = Trim(stripslashes($_POST['Ecommerce']));
    $SearchEngineOptimization = Trim(stripslashes($_POST['SearchEngineOptimization']));
    $Other = Trim(stripslashes($_POST['Other']));
    $Description = Trim(stripslashes($_POST['Description']));
    $Budget = Trim(stripslashes($_POST['Budget']));
    $AdditionalCommentsandQuestions = Trim(stripslashes($_POST['AdditionalCommentsandQuestions']));

    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($Name)=="") $validationOK=false;
    if (Trim($Telephone)=="") $validationOK=false;
    if (Trim($Email)=="") $validationOK=false;
    if (!$validationOK) {
    print "meta http-equiv=\"refresh\" content=\"0;URL=http://www.sparksolutions.net/support_error.html";
    }

    // prepare email body text
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Telephone: ";
    $Body .= $Telephone;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Company: ";
    $Body .= $Company;
    $Body .= "\n";
    $Body .= "Website: ";
    $Body .= $Website;
    $Body .= "\n";
    $Body .= "WebDesignandDevelopment: ";
    $Body .= $WebDesignandDevelopment;
    $Body .= "\n";
    $Body .= "Ecommerce: ";
    $Body .= $Ecommerce;
    $Body .= "\n";
    $Body .= "SearchEngineOptimization: ";
    $Body .= $SearchEngineOptimization;
    $Body .= "\n";
    $Body .= "Other: ";
    $Body .= $Other;
    $Body .= "\n";
    $Body .= "Description: ";
    $Body .= $Description;
    $Body .= "\n";
    $Body .= "Budget: ";
    $Body .= $Budget;
    $Body .= "\n";
    $Body .= "AdditionalCommentsandQuestions: ";
    $Body .= $AdditionalCommentsandQuestions;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, From: <$EmailFrom>);

    // redirect to success page
    if ($success){
    print "meta http-equiv=\"refresh\" content=\"0;URL=http://www.sparksolutions.net/thank_you.html";
    }
    else{
    print "meta http-equiv=\"refresh\" content=\"0;URL=http://www.sparksolutions.net/support_error.html";
    }
    ?>

    If anyone can help that would be great!!!

    Thanks,
    Nick
     
    NeighborNicks, Jul 19, 2009 IP
  2. DemCage

    DemCage Peon

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change line 69:

    $success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");
    PHP:
    or

    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    PHP:
    Both should work. :)

    Edit:

    You maybe want to change your redirect to something like this:

    "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.sparksolutions.net/support_error.html\">";
    PHP:
    or: http://de3.php.net/manual/en/function.header.php
     
    DemCage, Jul 19, 2009 IP
  3. Sergey Popov

    Sergey Popov Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just one note, since you exposed the code and url where this form will live, I recommend that you sanitize $EmailFrom variable before calling mail() function. Hijackers can inject additional headers to the email message using new line \n and CC:, and send spam using your code.
     
    Sergey Popov, Jul 20, 2009 IP
  4. NeighborNicks

    NeighborNicks Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    How would you do such a thing?

     
    NeighborNicks, Jul 21, 2009 IP
  5. Sergey Popov

    Sergey Popov Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    for example add these 2 lines somewhere before calling mail() function:

    
    $EmailFrom = str_replace("\n","",$EmailFrom);
    $EmailFrom = str_replace("\r","",$EmailFrom);
    
    PHP:

    Or, maybe your question was how would I inject additional headers using your form? :)
     
    Sergey Popov, Jul 21, 2009 IP
  6. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #6
    lol @ Sergey

    wasn't it that IF and Else were supposed to look like:

    if($some_var) {
    // some code here
    }

    where's his brackets on all the If's ?!?!?!?!!?
     
    ezprint2008, Jul 21, 2009 IP
  7. Sergey Popov

    Sergey Popov Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ezprint2008
    What did you mean to say? It looks like you are spamming here..

     
    Sergey Popov, Jul 21, 2009 IP