Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 63

Thread: PHP email form for dummies???

  1. #11
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Glad to help.

    Since this issue is now resolved, please mark the thread as Resolved to communicate to other members that this is no longer pending.
    - Josh

  2. #12
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    So, it didn't seem to work - also, something I am noticing is that even if someone clicks on Landscape Design and Construction AND Lighting, only lighting shows up in the email...

    Actually, if I didn't hit lighting this shows up (along with what I had before)


    Services: $0 - $500
    Budget: $0 - $500

    I apologize for being a pain in the ass.
    Last edited by katiebugla; 08-26-2011 at 03:24 PM.

  3. #13
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    <?php
    $to 
    "josh@gscapedesign.com";
    $subject "Greenscape Customer Inquiry";
    $message "Customer name:        " $_POST['name'] . "\r\n" .
    "Phone number:                    " $_POST['phone'] . "\r\n" .
    "Email:                           " $_POST['email'] . "\r\n" ."\r\n" .
    "Best Way to Contact:           " $_POST['contact'] . "\r\n" ."\r\n";

    $field = array('landscape design and construction''hardscape design and construction''grounds maintenance''irrigation and drainage systems''lighting');

    foreach(
    $field as $f) {
    if(
    $_POST[$f] != '' && isset($_POST[$f])) {
    $message .= "Services: ".$_POST[$f]."\r\n";
    }
    }

    $message .= "Budget:            " $_POST['budget'] . "\r\n" 

    $message .= "Anything Else:     " $_POST['other'] . "\r\n" 
     
    $from $_POST['email'];
    $headers "From: $from"\r\n";
    $headers "Bcc: kroge16@tigers.lsu.edu" "\r\n" ;
    mail($to,$subject,$message,$headers) ;
    ?>
    Will that read? I basically need it to read as such:

    Customer name: Katie
    Phone number: 1-555-555-5555
    Email: katiebugla@yahoo.com

    Best Way to Contact: Phone

    Budget: $0-500
    Services: lighting, grounds maintenance

    Anything Else: "I like your portfolio page." (text area)

  4. #14
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    You're right, it didn't parse the field names correctly. But I had a better, more elegant solution.

    Let's rename all of the checkboxes to the same name, as an array. The [] will indicate that it is an array. Change your checkboxes to this:
    Code:
    <label>
           	  <input name="serviceItem[]" type="checkbox" id="landscape design and construction" value="landscape design and construction" />
              <span class="form_text">Landscape Design &amp; Construction</span></label>
               <br />
           <label>
           	  <input name="serviceItem[]" type="checkbox" id="hardscape design and construction" value="hardscape design and construction" />
              <span class="form_text">Hardscape Design &amp; Construction</span></label>
              <br />
          <label>
           	  <input name="serviceItem[]" type="checkbox" id="grounds maintenance" value="grounds maintenance" />
              <span class="form_text">Grounds Maintenance</span></label>
              <br />
          <label>
           	  <input name="serviceItem[]" type="checkbox" id="irrigation and drainage systems" value="irrigation and drainage systems" />
              <span class="form_text">Irrigation &amp; Drainage Systems</span></label>
             <br />    
          <label>
           	  <input name="serviceItem[]" type="checkbox" id="lighting" value="lighting" />
              <span class="form_text">Lighting</span></label>

    We then loop through the serviceItem if it is set, and then append each value to $message

    Here's the PHP:
    PHP Code:
    $to "josh@gscapedesign.com";
        
    $subject "Greenscape Customer Inquiry";
        
    $message "Customer name: " $_POST['name'] . "\r\n" .
        
    "Phone number:            " $_POST['phone'] . "\r\n" .
        
    "Email:                    " $_POST['email'] . "\r\n" ."\r\n" .
        
    "Contact:                 " $_POST['contact'] . "\r\n" ."\r\n";
        
        
    $field = array('landscape design and construction''hardscape design and construction''grounds maintenance''irrigation and drainage systems''lighting''budget');
        
        if(isset(
    $_POST[serviceItem])) {
            if(isset(
    $_POST[serviceItem])) {
                 
    $message .= "Services: ".implode(", "$_POST[serviceItem])."\r\n";
            }
        }
        
        
    $message .= "Budget:                " $_POST['budget'] . "\r\n" 
         
        
    $from $_POST['email'];
        
    $headers "From: $from"\r\n";
        
    $headers "Bcc: kroge16@tigers.lsu.edu" "\r\n" ;
    mail($to,$subject,$message,$headers) ; 
    The result would be like this:
    Code:
    Customer name: Katie
    Phone number: 1-555-555-5555
    Email: katiebugla@yahoo.com
    
    Best Way to Contact: Phone
    
    Budget: $0-500
    Services: lighting, grounds maintenance
    This code also gives you much more flexibility, because you can add/remove checkboxes easily without having to modify your PHP code. Any additional checkboxes should have the name set to serviceItem[].

    I tested this out myself this time and it works.
    - Josh

  5. The Following User Says Thank You to JShor For This Useful Post:

    katiebugla (08-26-2011)

  6. #15
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Btw, I edited that last post. I didn't realize you wanted it like "Services: lighting, etc." The new code should do that.
    - Josh

  7. #16
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    I am going to test it again... just out of curiousity, does 'budget' need to be in the array?

  8. #17
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by JShor View Post
    Btw, I edited that last post. I didn't realize you wanted it like "Services: lighting, etc." The new code should do that.
    Hey, I don't really know enough to ask the questions in the right way... Thank you for being patient!

  9. #18
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    No problem. Also, this is dead code, I forgot to remove it:
    PHP Code:
    $field = array('landscape design and construction''hardscape design and construction''grounds maintenance''irrigation and drainage systems''lighting''budget'); 
    You can go ahead and erase that line. It doesn't do anything anymore. And budget didn't need to be in the array to begin with, but somehow my absent-minded self put it in there. :P
    - Josh

  10. #19
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    I've done so many test runs at this point I can't tell which test went with which trail, but the latest outcome (email side):
    Customer name: Katie
    Phone number: 1-XXX-XXX-XXXX
    Email: katiebugla@yahoo.com

    Contact: Phone

    Anything Else: Another test.
    katiebugla@yahoo.comBudget: $0 - $500
    Customer name: Katie
    Phone number: 1-XXX-XXX-XXXX
    Email: katiebugla@yahoo.com

    Contact: Phone

  11. #20
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Can you post your entire code that you're using (PHP + HTML)?

    Something must be wrong.
    - Josh

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
  •