1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Collecting values from a Drop-down box for a sendmail script.

Discussion in 'PHP' started by JSellnau_TSCC, Feb 6, 2010.

  1. #1
    I have this for the form in HTML
        <tr>
        <td>                <label for="service">Service Required <span class="red">*</span></label>
            <div align="left"><font size="-2" >(You can hold down the "Control" key on your keyboard while selecting multiple services.)</font></div>
    
      </td>
        <td><select id="service" name="service">
        <option>...</option>
    <option name="service" value="GeneralContact">General Contact</option>
    <option name="service" value="WebsiteServices">Website Services</option>
    <option name="service" value="TechnicalSupportServices">Technical Support Services</option>
    <option name="service" value="NetworkSupportServices">Network Support Services</option>
    <option name="service" value="CustomSystems">Custom Systems</option>
    
    </select> 
     </td> 
      </tr>
    HTML:
    and this for the code in php

        $services = $_POST['service']; // required
    
    PHP:
        $email_message .= "Service Required: ".clean_string($services)."\n";
    
    PHP:
    Now, no matter what I have tried the services required value will not send in the email. It comes out blank every time and it is getting quite annoying.


    Any ideas anyone?

    Thank you.
     
    JSellnau_TSCC, Feb 6, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    echo out $email_message; in your reply.

    also post the relevant code which sends the mail.
     
    danx10, Feb 6, 2010 IP
  3. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    	$email_message = "Contact Form details below.\n\n";
    	
    	function clean_string($string) {
    	  $bad = array("content-type","bcc:","to:","cc:","href");
    	  return str_replace($bad,"",$string);
    	}
    	
    	$email_message .= "Name: ".clean_string($name)."\n";
    	$email_message .= "Email: ".clean_string($email_from)."\n";
    	$email_message .= "Company: ".clean_string($company)."\n";
    	$email_message .= "Subject: ".clean_string($subject)."\n"; 
    	$email_message .= "Service Required: ".clean_string($services)."\n";
    	$email_message .= "Message: ".clean_string($message)."\n";
    	
    	
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);  
    
    PHP:
     
    JSellnau_TSCC, Feb 6, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    1. Remove the @, because your supressing errors!

    2. You added $email_subject within the mail() but $subject within $email_message??

    Use this, make sure all variables are defined correctly:

    <?php
      error_reporting(E_ALL);
      
      function clean_string($string)
      {
          $bad = array("content-type", "bcc:", "to:", "cc:", "href");
          return str_replace($bad, "", $string);
      }
      
      
      $email_to = "your@email.com";
    
      $email_from = "dan@google.com";
      $name = "Dan M.";
      $company = "Google";
      $subject = "Testing Email";
      $services = "PHP Coding";
      $message = "Testing the email...."
      
      $email_message = "Contact Form details below.\n\n";
      
      $email_message .= "Name: " . clean_string($name) . "\n";
      $email_message .= "Email: " . clean_string($email_from) . "\n";
      $email_message .= "Company: " . clean_string($company) . "\n";
      $email_message .= "Subject: " . clean_string($subject) . "\n";
      $email_message .= "Service Required: " . clean_string($services) . "\n";
      $email_message .= "Message: " . clean_string($message) . "\n";
      
      
      // create email headers
      $headers = 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
      
      
      mail($email_to, $subject, $email_message, $headers);
    ?>
    PHP:
     
    danx10, Feb 6, 2010 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Why do people do this? What possible value does it have?

    If you want to put something useful in, put "X-Client-IP: {$_SERVER['REMOTE_ADDR']}".
     
    SmallPotatoes, Feb 6, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    I agree, but I believe its because php has set it as an example (Example #2 -> http://php.net/manual/en/function.mail.php)
     
    danx10, Feb 6, 2010 IP
  7. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This doesn't help solve my problem though...
     
    JSellnau_TSCC, Feb 7, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    Soo ungrateful...

    You need to help me, so I can help you. Have you tried the code I posted?, any errors?, whats not solved?...
     
    danx10, Feb 7, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Your code for the submit page:

    <?php
      error_reporting(E_ALL);
     
      function clean_string($string)
      {
          $bad = array("content-type", "bcc:", "to:", "cc:", "href");
          return str_replace($bad, "", $string);
      }
     if(isset($_POST['submit'])){
     
      $email_to = "your@email.com";
    
      //make sure all of these match the name's on your input fields
      $email_from = strip_tags($_POST['email_from']);
      $name = strip_tags($_POST['name']);
      $company = strip_tags($_POST['company']);
      $subject = strip_tags($_POST['subject']);
      $service = strip_tags($_POST['service']);
      $message = strip_tags($_POST['message']);
     
      $email_message = "Contact Form details below.\n\n";
     
      $email_message .= "Name: " . clean_string($name) . "\n";
      $email_message .= "Email: " . clean_string($email_from) . "\n";
      $email_message .= "Company: " . clean_string($company) . "\n";
      $email_message .= "Subject: " . clean_string($subject) . "\n";
      $email_message .= "Service Required: " . clean_string($service) . "\n";
      $email_message .= "Message: " . clean_string($message) . "\n";
     
     
      // create email headers
      $headers = 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
     
     
      mail($email_to, $subject, $email_message, $headers);
      }
    ?>
    PHP:
    And your html for 'services' should be:

    <tr>
        <td>                <label for="service">Service Required <span class="red">*</span></label>
            <div align="left"><font size="-2" >(You can hold down the "Control" key on your keyboard while selecting multiple services.)</font></div>
    
      </td>
        <td><select id="service" name="service">
        <option>...</option>
    <option value="GeneralContact">General Contact</option>
    <option value="WebsiteServices">Website Services</option>
    <option value="TechnicalSupportServices">Technical Support Services</option>
    <option value="NetworkSupportServices">Network Support Services</option>
    <option value="CustomSystems">Custom Systems</option>
    
    </select>
     </td>
      </tr>
    Code (markup):
     
    Last edited: Feb 7, 2010
    danx10, Feb 7, 2010 IP
  10. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If I put this in the php file for $services

    $services = "PHP Coding";
    PHP:
    It sends that in the email. I need it to collect the answer from the drop-down box in the form and send that though.
     
    JSellnau_TSCC, Feb 7, 2010 IP
  11. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #11
    Read my above post, the problem was that you were assigning a name for each option when you only need to assign it to the select tag.
     
    danx10, Feb 7, 2010 IP
  12. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Then I am getting these errors using that code

    
    Notice: Undefined index: email_from in /home/pcanswe1/public_html/contact.php on line 15
    
    Notice: Undefined index: service in /home/pcanswe1/public_html/contact.php on line 19
    Code (markup):
    it is for the "email_from" line and the "services" line
     
    JSellnau_TSCC, Feb 7, 2010 IP
  13. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    after editing a few more things it is just the "service" tag that is causing issues.....

    It just doesn't seem to be collecting it from the form.
     
    JSellnau_TSCC, Feb 7, 2010 IP
  14. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #14
    danx10, Feb 7, 2010 IP
  15. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I tried yours several times and it doesn't even send the email to my address.....with mine it sends everything BUT the "service" response in the form

    It gives me the same error with the "strip_tags" command in there as well.

    This error:
    Notice: Undefined index: service in /home/pcanswe1/public_html/contact.php on line 19
    PHP:
     
    JSellnau_TSCC, Feb 7, 2010 IP
  16. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #16
    OK post both all your php code and complete html form which your using now. Snippets are no help.
     
    danx10, Feb 7, 2010 IP
    JSellnau_TSCC likes this.
  17. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #17
    OK here you go...

    This is the form...
              <form action="contact.php" method="post" id="contactform" name="contactform">
              
              <table width="575" border="0" cellpadding="5">
      <tr>
        <td>                <label for="name">your name <span class="red">*</span></label>
    </td>
        <td>                <input id="name" name="name" class="text" />
    </td>
      </tr>
      <tr>
        <td>                <label for="email">Your email <span class="red">*</span></label>
    </td>
        <td>                <input id="email" name="email" class="text" />
    </td>
      </tr>
      <tr>
        <td>                <label for="company">Company Name</label>
      </td>
        <td>                <input id="company" name="company" class="text" />
      </td> 
      </tr>
        <tr>
        <td>                <label for="subject">Subject</label>
      </td>
        <td>                <input id="subject" name="subject" class="text" />
      </td> 
      </tr>
      
    <tr>
        <td>                <label for="service">Service Required <span class="red">*</span></label>
            <div align="left"><font size="-2" >(You can hold down the "Control" key on your keyboard while selecting multiple services.)</font></div>
    
      </td>
        <td><select id="service" name="service">
        <option>...</option>
    <option value="GeneralContact">General Contact</option>
    <option value="WebsiteServices">Website Services</option>
    <option value="TechnicalSupportServices">Technical Support Services</option>
    <option value="NetworkSupportServices">Network Support Services</option>
    <option value="CustomSystems">Custom Systems</option>
    
    </select>
     </td>
      </tr>
      <tr>
        <td>                <label for="message">Message <span class="red">*</span></label>
      </td>
        <td><textarea id="message" name="message" rows="6" cols="50"></textarea></td> 
      </tr>
    
      <tr>
        <td colspan="2" align="center">                             <input type="image" name="imageField" id="imageField" src="images/but_send_message.gif" />
      </td>
      </tr>
    
    </table>
       </form>
    
    HTML:
    And this is the content of the contact.php file that send the email now just with the error for the "service" tag...
    <?php
    
      error_reporting(E_ALL);
    
    
    if(isset($_POST['email'])) {
        
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "js.pcanswers@gmail.com";
        $email_subject = "Contact Form Email from PCAnswers-usa.com. ";
        
        
        
        $name = $_POST['name']; // required
        $subject = $_POST['subject']; // required
        $email_from = $_POST['email']; // required
        
        $company = $_POST['company']; // required
    
        $service = $_POST['service']; // required
    
        $message = $_POST['message']; // required
        
        
        
        
        
        $error_message = "";
        $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!eregi($email_exp,$email_from)) {
          $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
    
      if(strlen($error_message) > 0) {
          died($error_message);
      }
        $email_message = "Form details below.\n\n";
        
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
        
        $email_message .= "Name: ".clean_string($name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Company: ".clean_string($company)."\n";
        $email_message .= "Subject: ".clean_string($subject)."\n"; 
        $email_message .= "Service Required: ".clean_string($service)."\n";
        $email_message .= "Message: ".clean_string($message)."\n";
        
        
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);  
    ?>
    
    <!-- include your own success html here -->
    
    Thank you for contacting us. We will be in touch with you very soon.
    
    <?
    }
    ?>
    
    
    PHP:
    and there you go....
     
    JSellnau_TSCC, Feb 7, 2010 IP
  18. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #18
    And for this I didn't mean to sound ungrateful....I am just getting very irritated with this problem. And I thank you for your help.
     
    JSellnau_TSCC, Feb 7, 2010 IP
  19. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #19
    HTML form:

    <form action="contact.php" method="post" id="contactform" name="contactform">
             
              <table width="575" border="0" cellpadding="5">
      <tr>
        <td>                <label for="name">Your Name <span class="red">*</span></label>
    </td>
        <td>                <input id="name" name="name" class="text" />
    </td>
      </tr>
      <tr>
        <td>                <label for="email">Your Email <span class="red">*</span></label>
    </td>
        <td>                <input id="email" name="email" class="text" />
    </td>
      </tr>
      <tr>
        <td>                <label for="company">Company Name</label>
      </td>
        <td>                <input id="company" name="company" class="text" />
      </td>
      </tr>
        <tr>
        <td>                <label for="subject">Subject</label>
      </td>
        <td>                <input id="subject" name="subject" class="text" />
      </td>
      </tr>
     
    <tr>
        <td>                <label for="service">Service Required <span class="red">*</span></label>
            <div align="left"><font size="-2" >(You can hold down the "Control" key on your keyboard while selecting multiple services.)</font></div>
    
      </td>
        <td><select id="service" name="service">
    <option value="">...</option>
    <option value="GeneralContact">General Contact</option>
    <option value="WebsiteServices">Website Services</option>
    <option value="TechnicalSupportServices">Technical Support Services</option>
    <option value="NetworkSupportServices">Network Support Services</option>
    <option value="CustomSystems">Custom Systems</option>
    
    </select>
     </td>
      </tr>
      <tr>
        <td>                <label for="message">Message <span class="red">*</span></label>
      </td>
        <td><textarea id="message" name="message" rows="6" cols="50"></textarea></td>
      </tr>
    
      <tr>
        <td colspan="2" align="center">                             <input type="image" name="imageField" id="imageField" src="images/but_send_message.gif" />
      </td>
      </tr>
    
    </table>
       </form>
    Code (markup):
    contact.php:

    <?php
    
      error_reporting(E_ALL);
    
    
    if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['service']) && !empty($_POST['message'])){
       
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "js.pcanswers@gmail.com";
        $email_subject = "Contact Form Email from PCAnswers-usa.com. ";
       
      
        $name = $_POST['name']; // required
        $subject = $_POST['subject']; // required
        $email_from = $_POST['email']; // required
       
        $company = $_POST['company']; // required
    
        $service = $_POST['service']; // required
    
        $message = $_POST['message']; // required
       
        $error_message = "";
    
        $email_exp = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";
        
        if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        }
    
    
        $email_message = "Form details below.\n\n";
       
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
       
        $email_message .= "Name: ".clean_string($name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Company: ".clean_string($company)."\n";
        $email_message .= "Subject: ".clean_string($subject)."\n";
        $email_message .= "Service Required: ".clean_string($service)."\n";
        $email_message .= "Message: ".clean_string($message)."\n";
       
       
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    
    if($error_message == "" && mail($email_to, $email_subject, $email_message, $headers)){
    //sucessfully sent
    ?>
    <!-- include your own success html here -->
    
    Thank you for contacting us. We will be in touch with you very soon.
    <?php
    } else {
    //email address invalid
    echo $error_message;
    }
    }
    ?>
    PHP:
     
    danx10, Feb 7, 2010 IP
  20. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #20
    that solution sends no email for me
     
    JSellnau_TSCC, Feb 7, 2010 IP