2016-04-23 13 views
-1

Dies begann als vorgefertigte Kontaktformular, das in einer HTML-Vorlage gebündelt kam. Alle Felder des Textfelds funktionieren einwandfrei, wenn Sie die Absenderadresse eingeben. Allerdings brauche ich Hilfe mit einem Checkbox-Abschnitt, den ich selbst hinzugefügt habe. Ich habe versucht, einige Nachforschungen anzustellen, aber ich kann nicht erreichen, dass das Skript alle ausgewählten Kontrollkästchen in die E-Mail einbezieht.So machen Sie PHP Kontaktformular sammeln Sie alle ausgewählten Kontrollkästchen

Hier ist mein Arbeits html:

<form class="nobottommargin" id="template-contactform" name="template-contactform" action="include/sendemail.php" method="post"> 

              <div class="form-process"></div> 

              <div class="col_half"> 
               <label for="template-contactform-name">Name <small>*</small></label> 
               <input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="sm-form-control required" /> 
              </div> 

              <div class="col_half col_last"> 
               <label for="template-contactform-email">Email <small>*</small></label> 
               <input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email sm-form-control" /> 
              </div> 

              <div class="clear"></div> 

              <div class="col_half"> 
               <label for="template-contactform-phone">Phone <small>*</small></label> 
               <input type="text" id="template-contactform-phone" name="template-contactform-phone" value="" class="sm-form-control required" /> 
              </div> 

              <div class="col_half col_last"> 
               <label for="template-contactform-budget">Budget</label> 
               <input type="text" id="template-contactform-budget" name="template-contactform-budget" value="" class="sm-form-control" /> 
              </div> 

              <div class="clear"></div> 


              <div class="col_full"> 
               <label for="template-contactform-services[]">Services Required: </label> 
               <input name="template-contactform-services[]" type="checkbox" value="Web-Design" />Web Design 
               <input name="template-contactform-services[]" type="checkbox" value="E-Commerce" />E-Commerce 
               <input name="template-contactform-services[]" type="checkbox" value="User-Experience" />User Experience 
               <input name="template-contactform-services[]" type="checkbox" value="Branding" />Branding 
               <input name="template-contactform-services[]" type="checkbox" value="Mobile-Design" />Mobile Design 
               <input name="template-contactform-services[]" type="checkbox" value="Search-Marketing" />Search Marketing 
              </div> 

              <div class="col_full"> 
               <label for="template-contactform-message">Deliverables &amp; Goals <small>*</small></label> 
               <textarea class="required sm-form-control" id="template-contactform-message" name="template-contactform-message" rows="4" cols="30" placeholder="List the specific deliverables, services, and goals required..."></textarea> 
              </div> 

              <div class="col_full"> 
               <label for="template-contactform-missing">Anything Missing?</label> 
               <textarea class="sm-form-control" id="template-contactform-missing" name="template-contactform-missing" rows="4" cols="30" placeholder="Is there anything else you think we should know?"></textarea> 
              </div> 

              <div class="col_full hidden"> 
               <input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="sm-form-control" /> 
              </div> 

              <div class="col_full"> 

               <!--<script src="https://www.google.com/recaptcha/api.js" async defer></script> 
               <div class="g-recaptcha" data-sitekey="your-recaptcha-site-key"></div>--> 

              </div> 

              <div class="col_full"> 
               <button class="button button-3d nomargin" type="submit" id="template-contactform-submit" name="template-contactform-submit" value="submit">Send Message</button> 
              </div> 

             </form> 

und hier ist meine php:

<?php 

require_once('phpmailer/PHPMailerAutoload.php'); 

$toemails = array(); 

$toemails[] = array(
      'email' => '[email protected]', // Your Email Address 
      'name' => 'Your Name' // Your Name 
     ); 

// Form Processing Messages 
$message_success = 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.'; 

// Add this only if you use reCaptcha with your Contact Forms 
$recaptcha_secret = 'your-recaptcha-secret-key'; // Your reCaptcha Secret 

$mail = new PHPMailer(); 

// If you intend you use SMTP, add your SMTP Code after this Line 


if($_SERVER['REQUEST_METHOD'] == 'POST') { 
if($_POST['template-contactform-email'] != '') { 

    $name = isset($_POST['template-contactform-name']) ? $_POST['template-contactform-name'] : ''; 
    $email = isset($_POST['template-contactform-email']) ? $_POST['template-contactform-email'] : ''; 
    $phone = isset($_POST['template-contactform-phone']) ? $_POST['template-contactform-phone'] : ''; 
    $budget = isset($_POST['template-contactform-budget']) ? $_POST['template-contactform-budget'] : ''; 
    $service = isset($_POST['template-contactform-services']) ? $_POST['template-contactform-services'] : ''; 
    $message = isset($_POST['template-contactform-message']) ? $_POST['template-contactform-message'] : ''; 
    $missing = isset($_POST['template-contactform-missing']) ? $_POST['template-contactform-missing'] : ''; 


    $subject = isset($subject) ? $subject : 'New Message From Contact Form'; 

    $botcheck = $_POST['template-contactform-botcheck']; 

    if($botcheck == '') { 

     $mail->SetFrom($email , $name); 
     $mail->AddReplyTo($email , $name); 
     foreach($toemails as $toemail) { 
      $mail->AddAddress($toemail['email'] , $toemail['name']); 
     } 
     $mail->Subject = $subject; 

     $name = isset($name) ? "Name: $name<br><br>" : ''; 
     $email = isset($email) ? "Email: $email<br><br>" : ''; 
     $phone = isset($phone) ? "Phone: $phone<br><br>" : ''; 
     $budget = isset($budget) ? "Budget: $budget<br><br>" : ''; 
     $service = isset($service) ? "Services Required: $service<br><br>" : ''; 
     $message = isset($message) ? "Deliverables & Goals: $message<br><br>" : ''; 
     $missing = isset($missing) ? "Anything Missing: $missing<br><br>" : ''; 

     $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : ''; 

     $body = "$name $email $phone $budget $service $message $missing $referrer"; 

     // Runs only when File Field is present in the Contact Form 
     if (isset($_FILES['template-contactform-file']) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK) { 
      $mail->IsHTML(true); 
      $mail->AddAttachment($_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name']); 
     } 

     // Runs only when reCaptcha is present in the Contact Form 
     if(isset($_POST['g-recaptcha-response'])) { 
      $recaptcha_response = $_POST['g-recaptcha-response']; 
      $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response); 

      $g_response = json_decode($response); 

      if ($g_response->success !== true) { 
       echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }'; 
       die; 
      } 
     } 

     $mail->MsgHTML($body); 
     $sendEmail = $mail->Send(); 

     if($sendEmail == true): 
      echo '{ "alert": "success", "message": "' . $message_success . '" }'; 
     else: 
      echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }'; 
     endif; 
    } else { 
     echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }'; 
    } 
} else { 
    echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }'; 
} 
} else { 
echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }'; 
} 

?> 

Vielen Dank im Voraus

Antwort

0

Sie haben verschiedene name Attribute den <input type="checkbox" /> Tag zu geben. Dann können Sie prüfen, ob ein Ankreuzfeld mit der Funktion isset() markiert ist.

+0

Danke, ich sehe, wie das funktioniert, aber wie kann ich es wie ein Array, wo meine E-Mail-Vorlage würde sagen Dienstleistungen erforderlich: Web, Grafik, etc. –

+0

diese E-Mail helfen Ihnen http: // stackoverflow. com/questions/4997252/get-post-from-multiple-checkboxes – fonfonx

+0

Als eine komplette php noob nicht wirklich :(Ich muss genau wissen, wie ich mein vorhandenes Skript ändern. Ich habe einige Sachen mit implode und is_array statt isset gesehen aber kann nicht viel Sinn machen und ich breche immer meine Form lol –

Verwandte Themen