Results 1 to 8 of 8

Thread: Contact form - unexpected T_ELSE

  1. #1
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Contact form - unexpected T_ELSE

    http://www.iankovi.com/sponsicontact.php

    I get Parse error: parse error, unexpected T_ELSE in /home/iankovi/public_html/sponsicontact.php on line 38

    PHP Code:
    <?php
    $to 
    'iankovi.com';
    $name trim($_POST['name']);
    $email trim($_POST['email']);
    $subject trim($_POST['subject']);
    $message trim($_POST['message']);
    $message wordwrap($message85); 

    if (empty(
    $name) || empty($email) || empty($subject) ||empty($message)) 
    {
    echo 
    'Please fill in and verify all fileds';

    if(
    preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i"$_POST['email'])) 

    echo 
    'Please enter a valid email address.';

    } else {

    $send=mail("$to""$email""$subject""message");

    if(
    $send)
    {
    echo 
    'Your message has been sent successfully! A Sponsi representive will get back to you shortly.';

    } else {
    echo 
    'There was an error sending the mail, please go back and try again.';

    } else {

    echo (
    '

    <div id=\"contactleft\">
      <h2>Contact customer service</h2>
      <span class=\"elevensize\">All fields should be filled in and verified</span>
      <form method=\"POST\">
      Name: <br />
      <input name=\"name\" type=\"text\" class=\"inputlong\" /> <br />
      Email Address: <br />
      <input name=\"email\" type=\"text\" class=\"inputlong\" /> <br />
      Subject: <br />
      <input name=\"subject\" type=\"text\" class=\"inputlong\" /> <br />
      Detailed Message: <br />
      <textarea name=\"message\" cols=\"5\" rows=\"10\" class=\"texarealong\"></textarea>
      <br />
      <input name=\"send\" type=\"submit\" id=\"contantbutton\" value=\"Send Message\" />
      </form>
      </div>
      
    '
    );

    }
    ?>
    I have another question what should I add to display $name in form rather then 'Nobody' or 'Unknown.' Maybe something to do with headers?

    Thanks!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    } else {
    echo 'There was an error sending the mail, please go back and try again.';
    
    } else {
    Two else statements in a row don't make sense. If you mean to close an if-else block before the second one, add another ending curly brace (}).
    what should I add to display $name in form rather then 'Nobody' or 'Unknown.' Maybe something to do with headers?
    I don't understand: where would you like $name to appear? Where will you get $name from if the form hasn't been POSTed yet?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Code:
    } else {
    echo 'There was an error sending the mail, please go back and try again.';
    
    } else {
    Two else statements in a row don't make sense. If you mean to close an if-else block before the second one, add another ending curly brace (}).I don't understand: where would you like $name to appear? Where will you get $name from if the form hasn't been POSTed yet?
    I somewhat fixed it, but it still isn't sending.

    Updated: http://www.iankovi.com/sponsicontact.php

    PHP Code:
    <?php
    $to 
    'iankovi.com';
    $name trim($_POST['name']);
    $email trim($_POST['email']);
    $subject trim($_POST['subject']);
    $message trim($_POST['message']);
    $message wordwrap($message85); 

    if(isset(
    $_POST['send']))
    {

    if (empty(
    $name) || empty($email) || empty($subject) ||empty($message)) 
    {

    echo 
    'Please fill in and verify all fileds';

    if(
    preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i"$_POST['email'])) 


    echo 
    'Please enter a valid email address.';

    } else {
    $send=mail('$to''$email''$subject');
    }

    if(
    $send)
    {
    echo 
    'Mail sent successfully.';
    }

    } else {
    echo 
    'There was an error, please go back and try again';
    }

    } else {

    echo 
    '

    <div id="contactleft">
      <h2>Contact customer service</h2>
      <span class="elevensize">All fields should be filled in and verified</span>
      <form action="" method="POST" class="margintenform">
      Name: <br />
      <input name="Name" type="text" class="inputlong" /> <br />
      Email Address: <br />
      <input name="Email" type="text" class="inputlong" /> <br />
      Subject: <br />
      <input name="Subject" type="text" class="inputlong" /> <br />
      Detailed Message: <br />
      <textarea name="Message" cols="5" rows="12" class="texarealong"></textarea>
      <br />
      <input name="send" type="submit" id="contantbutton" value="Send Message" />
      <br />
      </form>
      </div>

    '
    ; }
    ?>

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Firstly, "iankovi.com" isn't a valid email address.
    Secondly, you've encased the variables in single quotes, meaning that they won't be parsed; you're literally trying to send an email to $to.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anymore suggestions?
    PHP Code:
    <?php
    error_reporting
    (E_STRICT);

    $to 'iankovi@msn.com';
    $name trim($_POST['name']);
    $email trim($_POST['email']);
    $subject trim($_POST['subject']);
    $message trim($_POST['message']);
    $message wordwrap($message85); 

    if(isset(
    $_POST['send'])) {
        if ((empty(
    $name) || empty($email) || empty($subject) ||empty($message)) || (preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i"$_POST['email']))) {
            echo 
    'Please fill in and verify all fileds';
        } else {
            if(
    mail($to $email$subject$message)) {
                echo 
    'Mail sent successfully.';
            } else {
                echo 
    'There was an error, please go back and try again';
            }
        }
    } else {
    echo 
    '

    <div id="contactleft">
      <h2>Contact customer service</h2>
      <span class="elevensize">All fields should be filled in and verified</span>
      <form action="" method="POST" class="margintenform">
      Name: <br />
      <input name="Name" type="text" class="inputlong" /> <br />
      Email Address: <br />
      <input name="Email" type="text" class="inputlong" /> <br />
      Subject: <br />
      <select name="select" class="selectinput">
        <option selected="selected">&lt;Select&gt;</option>
        <option>Company</option>
        <option>Getting Started</option>
        <option>Logging In</option>
      </select>
      <br />
      Detailed Message: <br />
      <textarea name="Message" cols="5" rows="12" class="texarealong"></textarea>
      <br />
      <input name="send" type="submit" id="contantbutton" value="Send Message" />
      <br />
      </form>
      </div>

    '
    ; }
    ?>
    Thank you for all your help!

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You want to negate the return value of that preg_match() call with a NOT operator:
    Code:
    (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $_POST['email']))
    Also, the recommended line length for an email is 65, not 85 as you've used above.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you, that and getting rid of the caps in the input names fixed the problem.

    Edit; For some reason I am still not receving the emails?
    Last edited by ralitza; 02-25-2006 at 11:11 PM.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try printing out all the variables before calling mail() to see what they all contain. If they all look right, the only other thing I can think of is that the SMTP server you're using isn't working properly, or possibly that your email account is junking the email. This has been known to happen with MSN/HoTMaiL accounts.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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