Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with email script unexpected t_string error

    okay i am trying to write an email script and i am getting a parse error on this line i believe

    else if ($_POST[x] == "y") {

    i believe it is correct but here is the code for the form

    <?
    $form_block= "
    <form action=\"$_SERVER[PHP_SELF]\" method=\"post\">

    <table border=0 align=center>
    <tr>
    <td align=left>
    <p>First Name*: <input type=\"text\" name=\"firstname\" size=30 maxlength=25></p>
    </td>
    <tr>
    <td align=left>
    <p>Last Name*: <input type=\"text\" name=\"lastname\" size=30 maxlength=25></p>
    </td>
    </tr>
    <tr>
    <td align=left>
    <p>Email address*: <input type=\"text\" name=\"email\" size=27 maxlength=25></p>
    </td>
    </tr>
    <tr>
    <td align=center>
    <textarea rows=15 cols=45 name=\"commentsorquestions\">
    Please include any comments or questions here.*
    </textarea>
    </td>
    </tr>
    <tr>
    <td align=center>
    <input type=\"hidden\" name=\"x\" value=\"y\">
    <p><input type=\"submit\" value=\"Send\">
    <input type=\"reset\" value=\"Clear\"></p></td>
    </tr>
    <tr>
    <td align=left>*Indicates required field
    </td>
    </tr>
    </table>
    </form>";
    if ($_POST[x] != "y") {
    echo "$form_block";
    }
    else if ($_POST[x] == "y") {
    if ($_POST[firstname] == "") || ($_POST[lastname] == "") || ($_POST[email] == "") || ($_POST[commentsorquestions) == ""){
    // a field is not filled in
    $field_err = "<font color=red>Please fill in all required fields!</font>";
    $send= "no";
    }
    }
    if ($send != "no"){
    $to = "";
    $subject = "Feedback";
    $msg .= "Sender's First Name: $_POST[firstname]\n";
    $msg .= "Sender's Last Name: $_POST[lastname]\n";
    $msg .= "Email: $_POST[email]\n";
    $msg .= "Message: $_POST[commentsorquestions]\n";
    mail($to, $subject, $msg)
    echo "<P>Your message has been sent. Thank you for your feedback.<P>";
    }
    else if ($send == "no") {
    echo "$field_err";
    echo "$form_block";
    }
    }
    ?>
    </body>
    </html>

    any help would be much appreciated

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Please use [php] tags for code...try this:
    PHP Code:
      if ($_POST[x] != "y") {    
       echo 
    $form_block;
     } 
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Ok mate.
    1. Your mail() function needs to have a terminating semi-colon.
    2. very bottom:
    else if ($send == "no") {
    echo "$field_err";
    echo "$form_block";
    }
    }
    One to many closing braces. Remove it.
    3. The boolean logic is flawed (set up incorrectly). Use:
    (($_POST[firstname] == "") || ($_POST[lastname] == "") || ($_POST[email] == "") || ($_POST[commentsorquestions] == ""))
    Added the surrounding brackets to the entirety, and changed the commentsorquestions key to be inclosed in square brackets ([]), as it was closed with a regular bracket.

    Cheers!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i changed everything but i am still getting the error on that specific line

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    PHP Code:
     elseif ($_POST[x] == "y") { 
    maybe?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #6
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still getting the error and i have no clue why

  • #7
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any help would be much appreciated

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Since there were a number of changes, I recommend reposting the current code.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #9
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?
    $form_block= "
    <form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
    <table border=0 align=center>
    <tr>
    <td align=left>
    <p>First Name*: <input type=\"text\" name=\"firstname\" size=30 maxlength=25></p>
    </td>
    <tr>
    <td align=left>
    <p>Last Name*: <input type=\"text\" name=\"lastname\" size=30 maxlength=25></p>
    </td>
    </tr>
    <tr>
    <td align=left>
    <p>Email address*: <input type=\"text\" name=\"email\" size=27 maxlength=25></p>
    </td>
    </tr>
    <tr>
    <td align=center>
    <textarea rows=15 cols=45 name=\"commentsorquestions\">
    Please include any comments or questions here.*
    </textarea>
    </td>
    </tr>
    <tr>
    <td align=center>
    <input type=\"hidden\" name=\"x\" value=\"y\">
    <p><input type=\"submit\" value=\"Send\">
    <input type=\"reset\" value=\"Clear\"></p></td>
    </tr>
    <tr>
    <td align=left>*Indicates required field
    </td>
    </tr>
    </table>
    </form>";
    if ($_POST[x] != "y") {
    echo "$form_block";
    }
    else if ($_POST[x] == "y") {
    if (($_POST[firstname] == "") || ($_POST[lastname] == "") || ($_POST[email] == "") || ($_POST[commentsorquestions] == "")){
    // a field is not filled in
    $field_err = "<font color=red>Please fill in all required fields!</font>";
    $send= "no";
    }
    }
    if ($send != "no"){
    $to = "";
    $subject = "Feedback";
    $msg .= "Sender's First Name: $_POST[firstname]\n";
    $msg .= "Sender's Last Name: $_POST[lastname]\n";
    $msg .= "Email: $_POST[email]\n";
    $msg .= "Message: $_POST[commentsorquestions]\n";
    mail($to, $subject, $msg);
    echo "<P>Your message has been sent. Thank you for your feedback.<P>";
    }
    else if ($send == "no") {
    echo "$field_err";
    echo "$form_block";
    }

    ?>
    </body>
    </html>

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I see no syntax errors in the code you have currently posted.
    Although I don't have the SMTP set up on my pc right now, it appears to be working correctly otherwise. Please post the error message that you are receiving.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Parse error: parse error, unexpected T_STRING in "filename" on line 81
    i think the error must be caused by my html coding before this script because i just tested the script and it works so i don't have a clue what could cause this but if anyone has any ideas i would much appreciate them
    Last edited by phpnewb; 12-01-2006 at 03:23 AM.

  • #12
    mz_
    mz_ is offline
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've tested the script. On it's own, just copy and paste the above it works ok besides saying "Your message has been sent. Thank you for your feedback." and sending a blank email on first load.

    However when I add it to my html page with the rest of my content, I get
    "Parse error: syntax error, unexpected T_STRING in <filename> on line 111"
    which is the following line;

    <form id="contact" action=\"$_SERVER[PHP_SELF]\" method=\"post\">

    I've been looking for a good contact script, but everyone I have tried either don't validate, sends blank emails (on 1st load), or has errors.

    No luck I guess.

    edit:

    If someone wants to see my entire contact.php page, and can fix it up for me, I'd be happy.
    My server uses Apache 1.3.37 and PHP 4.4.4, Thanks.
    Last edited by mz_; 12-01-2006 at 05:49 PM.

  • #13
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Start by fixing the index errors in each occurrence of the following -
    Code:
    $_SERVER[PHP_SELF] -----------> $_SERVER['PHP_SELF']
    $_POST[x] --------------------> $_POST['x']
    $_POST[firstname] ------------> $_POST['firstname']
    $_POST[lastname] -------------> $_POST['lasname']
    $_POST[email] ----------------> $_POST['email']
    $_POST[commentsorquestions] --> $_POST['commentsorquestions']
    The first one is probably what is causing the fatal error. Also, add the following after your opening php tag and see what you get -
    PHP Code:
    error_reporting(E_ALL); 
    The reason why it sends a blank message on the first pass through the code is that the following logic is flawed -
    PHP Code:
    if ($send != "no"){ 
    $send is not set to any value in the code except within a conditional statement that is not set. Therefore, on the first pass through the code $send is a null and null is not equal to "no", so it executes the mail(....) function.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #14
    New Coder
    Join Date
    Nov 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Even after those changes i am still getting the same error. If this error does not occur within the script could something else be causing it. How do I keep it from sending an email on the first load.

    <?
    error_reporting(E_ALL);
    $form_block= "
    <form action=\"$_SERVER['PHP_SELF']\" method=\"post\">
    <table border=0 align=center>
    <tr>
    <td align=left>
    <p>First Name*: <input type=\"text\" name=\"firstname\" size=30 maxlength=25></p>
    </td>
    <tr>
    <td align=left>
    <p>Last Name*: <input type=\"text\" name=\"lastname\" size=30 maxlength=25></p>
    </td>
    </tr>
    <tr>
    <td align=left>
    <p>Email address*: <input type=\"text\" name=\"email\" size=27 maxlength=25></p>
    </td>
    </tr>
    <tr>
    <td align=center>
    <textarea rows=15 cols=45 name=\"commentsorquestions\">
    Please include any comments or questions here.*
    </textarea>
    </td>
    </tr>
    <tr>
    <td align=center>
    <input type=\"hidden\" name=\"x\" value=\"y\">
    <p><input type=\"submit\" value=\"Send\">
    <input type=\"reset\" value=\"Clear\"></p></td>
    </tr>
    <tr>
    <td align=left>*Indicates required field
    </td>
    </tr>
    </table>
    </form>";
    if ($_POST['x'] != "y") {
    echo "$form_block";
    }
    else if ($_POST['x'] == "y") {
    if (($_POST['firstname'] == "") || ($_POST['lastname'] == "") || ($_POST['email'] == "") || ($_POST['commentsorquestions'] == "")){
    // a field is not filled in
    $field_err = "<font color=red>Please fill in all required fields!</font>";
    $send = "no";
    }
    }
    if ($send != "no"){
    $to = "";
    $subject = "Feedback";
    $mailheaders = "From: My Web site <> \n";
    $msg .= "Sender's First Name: $_POST[firstname]\n";
    $msg .= "Sender's Last Name: $_POST[lastname]\n";
    $msg .= "Email: $_POST[email]\n";
    $msg .= "Message: $_POST[commentsorquestions]\n";
    mail($to, $subject, $msg);
    echo "<P>Your message has been sent. Thank you for your feedback.<P>";
    }
    else if ($send == "no") {
    echo "$field_err";
    echo "$form_block";
    }

    ?>
    </body>
    </html>

    this is the code after the previous changes
    Last edited by phpnewb; 12-01-2006 at 10:47 PM.

  • #15
    mz_
    mz_ is offline
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it all but working except the mail send on first load. What can we do to fix that?

    On first load, it shows the form, with "Your message has been sent. Thank you for your feedback."

    Suggestions on what to add/change?

    I use a style sheet on the form, but you'll get the basic idea. (just piece them together)

    Code:
    <?php
    $form_block= "
            <form id=\"contact\" action=\"$_SERVER[PHP_SELF]\" method=\"post\">
              <div class=\"row1\">
                <span class=\"formlabel\">Your name *</span>
                <span class=\"forminput\"><input type=\"text\" name=\"firstname\" /></span>
              </div>
              <div class=\"row1\">
                <span class=\"formlabel\">Your email address *</span>
                <span class=\"forminput\"><input type=\"text\" name=\"email\" /></span>
              </div>
              <div class=\"row1\">
                <span class=\"formlabel\">Your message *</span>
                <span class=\"forminput\"><textarea cols=\"34\" rows=\"5\" name=\"commentsorquestions\" class=\"textarea\"></textarea></span>
              </div>
              <div class=\"spacer\">&nbsp;</div>
              <div class=\"row1\">
                <span class=\"formlabel\"></span>
                <span class=\"forminput\"><input type=\"hidden\" name=\"x\" value=\"y\">
                                        <p><input type=\"submit\" value=\"send\" class=\"submit\" /></p></span>
              </div>
            </form>";
    PHP Code:
    if ($_POST['x'] != "y") {
       echo 
    $form_block;
    }
    else if (
    $_POST['x'] == "y") {
    if ((
    $_POST['firstname'] == "") || ($_POST['email'] == "") || ($_POST['commentsorquestions'] == "")){
    // a field is not filled in
    $field_err "<p><font color=red>Please fill in all required fields!</p></font>";
    $send "no";
    }
    }
    if (
    $send != "no") {
    $to "";
    $subject "Feedback";
    $headers "From: $email" "\r\n" .
               
    "Reply-To: $email" "\r\n" .
               
    'X-Mailer: PHP/' phpversion();
    $msg .= "Sender's First Name: $_POST[firstname]\n";
    $msg .= "Email: $_POST[email]\n";
    $msg .= "Message: $_POST[commentsorquestions]\n";
    mail($to$subject$msg$headers);
    echo 
    "<p>Your message has been sent. Thank you for your feedback.</p>";
    }
    else if (
    $send == "no") {
    echo 
    "$field_err";
    echo 
    "$form_block";
    }
    ?> 
    Last edited by mz_; 12-01-2006 at 11:59 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •