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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Location
    South Lincolnshire, UK
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    elements in form not sending to mail

    Hi, just learning php so please be gentle with me.

    I have created a form and its associated php handler but am unable to make the form submit the fields in the form. Any suggestions would be much appreciated

    The form is sent to who ever is selected but the senders details are not included other than the email address and would like the other details from the form to be included. I have probably done something simple but for the life of me I cant find it or make it work.

    Code:
    <form action="" method="POST">
            <b> </b>
            <table width="85%" border="0" align="center">
              <tr> 
                <td width="40%" valign="top"><b>Please enter your name:</b></td>
                <td width="60%" valign="top"> 
                  <input type="text" name="name" size="30">
                </td>
              </tr>
              <tr> 
                <td width="40%" valign="top"> 
                  <b> Please choose a contact: </b> </td>
                <td width="60%" valign="top"> 
                  <select name="contact">
                    <option value="default">Choose who to contact</option>
                    <option value="1"> Membership </option>
                    <option value="2"> Our Way </option>
                    <option value="3"> Meets Co-Ordinator </option>
                    <option value="4"> Trades Officer </option>
                    <option value="5"> Treasurer </option>
                    <option value="6"> Forum Adminsitration </option>
                    <option value="7"> Publicity </option>
                    <option value="8"> Secretary </option>
                    <option value="9"> Information </option>
                  </select>
                </td>
              </tr>
              <tr> 
                <td width="40%" valign="top"><b>Please enter a subject:</b></td>
                <td width="60%" valign="top"> 
                  <input type="text" name="subject" size="30">
                </td>
              </tr>
              <tr> 
                <td width="40%" valign="top"> 
                  <b> Please enter your email address:</b></td>
                <td width="60%" valign="top"> 
                  <input type="text" name="email" size="30">
                </td>
              </tr>
              <tr> 
                <td width="40%" valign="top"> 
                  <b> Please enter your message: </b></td>
                <td width="60%" valign="top"> 
                  <textarea name="message" cols="60" rows="10">
         
         </textarea>
                </td>
              </tr>
              <tr> 
                <td width="40%">&nbsp; </td>
                <td width="60%" valign="top"> 
                  <input type="submit" value="Submit" name="submit_1">
                  <input type="reset" value="Reset" name="reset">
                </td>
              </tr>
            </table>
    
      </form>
    Code:
    <?php
    
    if(isset($_POST['submit_1'])) {
    
    $name = $_POST['name'];
    $contact = $_POST['contact'];
    $subject = $_POST['subject'];
    $email = $_POST['email'];
    $message  = $_POST['message'];
    $error = "";
    $headers = 'From:'.' '. $email;
    
    if($name=="") $error.="*Please enter a name"."<br>";
    if($subject=="") $error.="*Please enter a subject"."<br>";
    if($email=="") $error.="*Please enter a email"."<br>";
    if($message=="") $error.="*Please enter a message"."<br>";
    
    switch ($contact){
         case 1:
            $contact = "membership@sbmcc.co.uk"; // Shaun //
            break;
         case 2:
             $contact = "ourway@sbmcc.co.uk"; // Jo //
             break;
         case 3:
             $contact = "meets@sbmcc.co.uk"; // Barry //
             break;
    		 case 4:
             $contact = "trades@sbmcc.co.uk"; // Paul //
             break;
    		 case 5:
             $contact = "treasurer@sbmcc.co.uk"; // Wal //
             break;
    		 case 6:
             $contact = "webmaster@sbmcc.co.uk"; // Ian //
             break;
    		 case 7:
             $contact = "publicity@sbmcc.co.uk"; // Trev //
             break;
    		 case 8:
             $contact = "secretary@sbmcc.co.uk"; // Mike //
             break;
    		 case 9:
             $contact = "info@sbmcc.co.uk"; // Mike //
             break;
         default:
              $contact = "info@sbmcc.co.uk"; // Mike //
              break;
    }
    
      if($error==""){
        
          if(mail($contact, $subject, $message, $headers)){
       echo "<p><b><font color=#f00>Thank You $name</b></p><p>We will be in touch as soon as possible.</font></p><br /><br />"; 
    }
      else {
    echo " <p><b><font color=#f00>Email failed to send</font></b></p><br /><br /> ";
    }
    
    
    
    }
    else{
        echo "<div align='center'>". $error ."</div>";
    }
    
    }
      else ;
    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Can you clarify--

    You DO get an email sent? It's just the wrong/missing stuff in the email that's the problem?

    Or is the email not being sent at all?

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Location
    South Lincolnshire, UK
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for lack of clarification. I do get an email sent but it only contains the message section and none of the other information (Name, Subject etc)

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    To make sure your form data is coming across successfully, do
    PHP Code:
    echo "<pre>".print_r($_POST)."</pre>"
    Make sure your $subject variable contains the correct value by echoing it.

  • #5
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    I don't see anywhere in your code where you do anything with 'name' other than check if it's there.

    Which came first - the chicken or the egg? The egg... [ticket closed]
    If a tree falls... does it make a sound? Yes.............. [ticket closed]

  • #6
    New to the CF scene
    Join Date
    Dec 2008
    Location
    South Lincolnshire, UK
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    To make sure your form data is coming across successfully, do
    PHP Code:
    echo "<pre>".print_r($_POST)."</pre>"
    Anywhere in particular, I suppose it should go near the top. I'll give it a go and see what happens.

    Just tried adding the echo and have come up with the following
    Code:
    Array ( [name] => Harry the Spider (Test) [contact] => 2 [subject] => Test [email] => elizium@ladt.org [message] => Test [submit_1] => Submit )
    
    1
    The above appears on the webpage contact form rather than transferring the information in the fields to
    the email that is to be sent out. Very frustrating. Suppose I still have a lot to learn about the php lark
    Last edited by Jo Mutch; 12-16-2008 at 11:15 PM. Reason: added stuff


  •  

    Posting Permissions

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