Page 4 of 7 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 63

Thread: PHP email form for dummies???

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

    Default

    The best way to prevent spam is by using CAPTCHA. Also, please re-post the final code you're using so we can see what's causing the data to double.
    - Josh

  2. #32
    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";
        
    if(isset(
    $_POST[serviceItem])) {
    if(isset(
    $_POST[serviceItem])) {
    $message .= "Services: ".implode(", "$_POST[serviceItem])."\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) ;   
    ?>

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

    Default

    And here is the html with the submit button remedy you suggested...
    HTML Code:
    <form action="email_form.php" method="post" name="contact_gscape" id="contact_gscape" onsubmit="document.getElementById('submit_btn').disabled = 'disabled'">
          <span id="sprytextfield1">
          <label for="name"><span class="form_text">Name</span></label>
          <input type="text" name="name" id="name" />
          <span class="textfieldRequiredMsg">A contact name is required.</span></span>
          <br />
          <span id="sprytextfield2">
          <label for="phone" class="form_text">Phone Number</label>
          <input type="text" name="phone" id="phone" />
          <span class="textfieldRequiredMsg">A phone number is required.</span><span class="textfieldInvalidFormatMsg">Please enter a valid phone number.</span></span>
          <br />
          <span id="sprytextfield3">
          <label for="email" class="form_text">Email</label>
          <input type="text" name="email" id="email" />
          <span class="textfieldRequiredMsg">An email address is required.</span><span class="textfieldInvalidFormatMsg">Please enter a valid email address.</span></span>
          </p>
          <span id="contact">
          <label for="label">What is the best way to contact you?</label>
          <select name="contact" size="1" id="contact">
            <option value="Phone">Phone</option>
            <option value="Email">Email</option>
          </select>
          <span class="selectRequiredMsg">Please select an item.</span></span>
          </p>
            <span class="form_text">What Greenscape services would you like to know more about?</span>      
            <br />
          <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>
            </p>
             <span class="form_text">What is your budget?</span><span id="level1">
             <label for="budget"></label>
             <select name="budget" id="budget">
               <option value="$0 - $500">$0 - $500</option>
               <option value="$501-$1000">$501-$1000</option>
               <option value="$1001-$5000">$1001-$5000</option>
               <option value="$5000+">$5000+</option>
             </select>
             <span class="selectRequiredMsg">Please select an item.</span></span>
            </p>
            <span id="sprytextarea1">
            <label for="other" class="form_text">Anything else?</label>
            <br />
            <textarea name="other" id="other" cols="45" rows="2"></textarea></span><br />
         <input name="Submit" type="submit" value="Email Us" id="submit_btn" />
      </form>

  4. #34
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Should I perhaps use this code instead of trying to build my own???

    http://www.work-at-home-forum.com/web-design-8/free-php-contact-form-with-spam-protection-12714.html

  5. #35
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    I see on another forum that someone has done something with php that starts like this

    PHP Code:
    $from $_POST['from'];
    if(IsSet(
    $from)){ 
    Would putting some sort of modification that way be beneficial?

    I really don't know what I am doing, so if that was out of left field, I apologize.

  6. #36
    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";
        
    if(isset(
    $_POST[serviceItem])) {
    if(isset(
    $_POST[serviceItem])) {
    $message .= "Services: ".implode(", "$_POST[serviceItem])."\r\n";
    }
    }
        
    "Budget:            " $_POST['budget'] . "\r\n" 
    "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) ;   
    ?>
    Ok, I took the $message tags off of "Budget" and "Anything Else" - and now I am getting just one message (YAY!)... however, it is not populating anything from the text area or 'other'

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

    Default

    Oh, I see why there were duplicate messages now. The first $message variable string was never terminated, so it was essentially a $message within $message causing it to duplicate (and that's why your solution worked).

    Try using this:
    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";
        
    if(isset(
    $_POST[serviceItem])) {
    if(isset(
    $_POST[serviceItem])) {
    $message .= "Services: ".implode(", "$_POST[serviceItem])."\r\n";
    }
    }
     
    $budget =    
    "Budget:            " $_POST['budget'] . "\r\n" 
    "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.$budget,$headers) ;   
    ?>
    - Josh

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

    Default

    Okay - tried that and neither the budget or other showed up - but i am doing some trails to see what I can do.

  9. #39
    Join Date
    Jul 2011
    Posts
    113
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Done some trials - here is what I have:
    PHP Code:
    <?php
    $to 
    "katiebugla@yahoo.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" .
    "Budget:                             " $_POST['budget'] . "\r\n" ;
     
    if(isset(
    $_POST[serviceItem])) {
    if(isset(
    $_POST[serviceItem])) {
    $message .= "Services: ".implode(", "$_POST[serviceItem])."\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) ;   
    ?>
    And it displays as such:

    Customer name: John Doe
    Phone number: 1-xxx-xxx-xxxx
    Email: blah@yahoo.com

    Best way to contact: Email

    Budget: $1001-$5000
    Services: hardscape design and construction, grounds maintenance, lighting
    Anything Else: For the love of meatballs, work.


    Thank you for your patience - would you mind directing me to some info on making this more secure (i.e. less spam)?

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

    Default

    Name this file captcha.php:

    PHP Code:
    <?php.

    session_start();
     
    $str "";
    $length 0;
    for (
    $i 0$i 6$i++) {
        
    // these numbers represent ASCII table (small letters)
        
    $str .= chr(rand(97122));
    }
     
    //md5 letters and saving them to session
    $letters md5($str);
    $_SESSION['letters'] = $letters;
     
    //determine width and height for our image and create it
    $imgW 300;
    $imgH 100;
    $image imagecreatetruecolor($imgW$imgH);
     
    //setup background color and border color
    $backgr_col imagecolorallocate($image238,239,239);
    $border_col imagecolorallocate($image208,208,208);
     
    //let's choose color in range of purple color
    $text_col imagecolorallocate($imagerand(70,90),rand(50,70),rand(120,140));
     
    //now fill rectangle and draw border
    imagefilledrectangle($image00$imgW$imgH$backgr_col);
    imagerectangle($image00$imgW-1$imgH-1$border_col);
     
    //save fonts in same folder where you PHP captcha script is
    //name these fonts by numbers from 1 to 3
    //we shall choose different font each time
    $fn rand(1,3);
    $font $fn ".ttf";
     
    //setup captcha letter size and angle of captcha letters
    $font_size $imgH 2.2;
    $angle rand(-15,15);
    $box imagettfbbox($font_size$angle$font$str);
    $x = (int)($imgW $box[4]) / 2;
    $y = (int)($imgH $box[5]) / 2;
    imagettftext($image$font_size$angle$x$y$text_col$font$str);
     
    //now we should output captcha image
    header("Content-type: image/png");
    imagepng($image);
    imagedestroy ($image);

    ?>
    Insert this into your form HTML:
    Code:
    <p>Insert letters from image below:</p>
    <img src="http://yourdomain.com/captcha.php" width="300" height="100" alt="simple PHP captcha" />
    <input type="text" name="captcha" />
    And modify your form's PHP to this:
    PHP Code:
    <?php

    session_start
    ();

    if (!
    $is_valid) {
        echo 
    'Letters from simple PHP captcha have not been entered correctly....';
    } else {
    $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";
        
    if(isset(
    $_POST[serviceItem])) {
    $message .= "Services: ".implode(", "$_POST[serviceItem])."\r\n";
    }
     
    $budget =    
    "Budget:            " $_POST['budget'] . "\r\n" 
    "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.$budget,$headers) ;   

    $is_valid $_SESSION['letters'] == md5(strtolower($_POST['captcha']));
     
        echo 
    'CAPTCHA has been entered correctly.';
    }
    ?>
    That will add a CAPTCHA image, where users have to enter the letters they see into the textbox. Robots can't do this, so it prevents spam.

    Script credit:
    http://stuntsnippets.com/simple-php-captcha/
    - Josh

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

    katiebugla (09-01-2011)

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
  •