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.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    1.12°W 52.67°N
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Feedback form not 100%

    First off here's the code...

    Code:
    <form name="contact" method="post" action="contact.php">
    Your Name: <input type="text" name="Name"><br /><br />
    Your Email: &nbsp;<input type="text" name="Email"><br /><br />
    Subject: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="Subject"><br /><br />
    Reason:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <select name="Reason">
       <option value="1">General Feedback</option>
       <option value="2">Advertising</option>
       <option value="3">Site Suggestion</option>
       <option value="4">Other Comment</option>
     </select><br /><br />
    Message:<br />
     <textarea name="Message" cols="30" rows="8"></textarea><br />
     <input type="submit" name="submit" value="Contact Us">
    </form>
    
    <?php
    
    $emailSubject = $_POST['Subject'];
    $emailMessage = $_POST['Message'];
    $emailFrom = $_POST['Email'];
    $emailFromName = $_POST['Name'];
    
    $emailList[1] = 'myemailaddyhere';
    $emailList[2] = 'myemailaddyhere';
    $emailList[3] = 'myemailaddyhere';
    $emailList[4] = 'myemailaddyhere :( ';
    
    $emailTo = $emailList[$_POST['Reason']];
    
    if (!empty($emailFrom)) {
    $emailHeaders = 'From: "' . $emailName . '" <' . $emailFrom . '>';
    } else {
        $emailHeaders = 'From: "Auriga" <myemailaddyhere>';
    }
    
    if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
        echo 'The email address entered is invalid.';
    } elseif (empty($emailSubject)) {
        echo 'You must enter a valid subject.';
    } elseif (empty($emailMessage)) {
        echo 'You must enter a message to send to our team.';
    } elseif (($_POST['Reason'] < 1) || ($_POST['Reason'] > 3)) {
        echo 'You have selected an invalid department.';
    } else {
        // The sending code here
    }
        /* Send Email */
        if (mail($emailTo, $emailSubject, $emailMessage, $emailHeaders)) {
            echo 'You message has been sent!';
        } else {
            echo 'There was an internal error whilst sending your email.<br>';
            echo 'Please try again later.';
        }
    ?>
    Which is from an article at php nerds (http://www.phpnerds.com/article/buil...ontact-form/1).

    My only problem is that when you first load the form up on the page (www.auriga.org.uk/contact.php) you'll notice that under the 'contact us' button it says...

    The email address entered is invalid.
    You must enter a valid subject.
    etc
    etc

    Even before you fill out the form.

    the only thing is i'm not sure what's wrong, i'm guessing something is in the wrong place...

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Code:
    <form name="contact" method="post" action="contact.php">
    Your Name: <input type="text" name="Name"><br /><br />
    Your Email: &nbsp;<input type="text" name="Email"><br /><br />
    Subject: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="Subject"><br /><br />
    Reason:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <select name="Reason">
       <option value="1">General Feedback</option>
       <option value="2">Advertising</option>
       <option value="3">Site Suggestion</option>
       <option value="4">Other Comment</option>
     </select><br /><br />
    Message:<br />
     <textarea name="Message" cols="30" rows="8"></textarea><br />
     <input type="submit" name="submit" value="Contact Us">
    </form>
    
    <?php
    if(isset($_POST['submit'])){
    
    $emailSubject = $_POST['Subject'];
    $emailMessage = $_POST['Message'];
    $emailFrom = $_POST['Email'];
    $emailFromName = $_POST['Name'];
    
    $emailList[1] = 'myemailaddyhere';
    $emailList[2] = 'myemailaddyhere';
    $emailList[3] = 'myemailaddyhere';
    $emailList[4] = 'myemailaddyhere :( ';
    
    $emailTo = $emailList[$_POST['Reason']];
    
    if (!empty($emailFrom)) {
    $emailHeaders = 'From: "' . $emailName . '" <' . $emailFrom . '>';
    } else {
        $emailHeaders = 'From: "Auriga" <myemailaddyhere>';
    }
    
    if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
        echo 'The email address entered is invalid.';
    } elseif (empty($emailSubject)) {
        echo 'You must enter a valid subject.';
    } elseif (empty($emailMessage)) {
        echo 'You must enter a message to send to our team.';
    } elseif (($_POST['Reason'] < 1) || ($_POST['Reason'] > 3)) {
        echo 'You have selected an invalid department.';
    } else {
        // The sending code here
    }
        /* Send Email */
        if (mail($emailTo, $emailSubject, $emailMessage, $emailHeaders)) {
            echo 'You message has been sent!';
        } else {
            echo 'There was an internal error whilst sending your email.<br>';
            echo 'Please try again later.';
        }
    }
    ?>

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    1.12°W 52.67°N
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've added in the bits you highlighted in red and get the following...

    Parse error: parse error, unexpected $ in /home/auriga/public_html/contact.php on line 117

  • #4
    Regular Coder
    Join Date
    Apr 2005
    Location
    1.12°W 52.67°N
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's ok, forget that - i found it out...Thankyou!


  •  

    Posting Permissions

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