Ankündigung

Einklappen
Keine Ankündigung bisher.

PHPmailer Probleme bei Select-Auswahl

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • PHPmailer Probleme bei Select-Auswahl

    Hallo liebe Forum-Mitglieder,
    ich brauche ganz dringend Hilfe bei der Änderung eines Kontaktformulares.
    Das normale Kontaktformular (PHPmailer) funktioniert, soll aber um 4 zusätzliche Abfragen ergänzt werden.
    Das sind 3 Fragen mit Select-Auswahl und 1 normales Textfeld.
    Ich bekomme es seit Tagen nicht hin, die Select-Auswahl in der PHP-Datei einzubauen, damit die Antworten ordentlich in der E-Mail erscheinen.

    Mein Formular sieht im oberen Teil so aus:

    HTML-Code:
    <div class="row">
                             <div class="form-group col-md-6">
                                    <div class="form-group">
                                    <label for="frage1">Hier kommt Frage 1 hin mit Auswahl</label>
                                    <select  name="frage1" class="form-control" id="frage1">
                                        <option value="Auswahl">bitte wählen Sie aus</option>
                                        <option value="ja">ja</option>
                                        <option value="nein">nein</option>
                                    </select>
                                </div>
                                </div>
                                <div class="form-group col-md-6">
                                     <label for="frage2">Frage 2 als Textfeld*</label>
                                        <input type="text" aria-required="true" required name="widget-contact-form-frage2
    " class="form-control required frage2" placeholder="Hier der Platzhalter*">
                                </div>    
                                </div>
    
                                    <div class="row">
                             <div class="form-group col-md-6">
                                    <div class="form-group">
                                    <label for="frage3">Hier kommt Frage 3 hin mit Auswahl</label>
                                    <select  class="form-control" id="frage3">
                                        <option value="Auswahl">bitte wählen Sie aus</option>
                                        <option value="ja">ja</option>
                                        <option value="nein">nein</option>
                                    </select>
                                </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <div class="form-group">
                                    <label for="frage4">Hier kommt Frage 4 hin mit Auswahl</label>
                                    <select  class="form-control" id="frage4">
                                        <option value="Auswahl">bitte wählen Sie aus</option>
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                    </select>
                                </div>
                                </div>    
                                </div>
    
    
                                <div class="row">
                                    <div class="form-group col-md-6">
                                        <label for="vorname">Vorname*</label>
                                        <input type="text" aria-required="true" required name="widget-contact-form-vorname" class="form-control required vorname" placeholder="Ihr Vorname">
                                    </div>
                                   <div class="form-group col-md-6">
                                        <label for="nachname">Nachname*</label>
                                        <input type="text" aria-required="true" required name="widget-contact-form-nachname" class="form-control required nachname" placeholder="Ihr Nachname">
                                    </div>
                                </div>
    
                                <div class="row">
                                    <div class="form-group col-md-6">
                                        <label for="phone">Telefon*</label>
                                        <input type="text" aria-required="true" required name="widget-contact-form-phone" class="form-control required phone" placeholder="Ihre Telefonnummer">
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label for="email">Email*</label>
                                        <input type="email" aria-required="true" required name="widget-contact-form-email" class="form-control required email" placeholder="Ihre Email-Adresse">
                                    </div>
                                </div>


    Das PHP-Dokument sieht so aus:

    PHP-Code:
    <?php
    session_cache_limiter
    ('nocache');
    header('Expires: ' gmdate('r'0));
    header('Content-type: application/json');


    use 
    PHPMailer\PHPMailer\PHPMailer;
    use 
    PHPMailer\PHPMailer\Exception;

    require 
    'php-mailer/src/Exception.php';
    require 
    'php-mailer/src/PHPMailer.php';
    //require 'path/to/PHPMailer/src/SMTP.php';

    $mail = new PHPMailer();

    // Enter your email address. If you need multiple email recipes simply add a comma: email@domain.com, email2@domain.com
    $to "info@meine-email.de";

    // Add your reCaptcha Secret key if you wish to activate google reCaptcha security
    $recaptcha_secret_key '';



    // Form Fields

    $vorname = isset($_POST["widget-contact-form-vorname"]) ? $_POST["widget-contact-form-vorname"] : null;
    $nachname = isset($_POST["widget-contact-form-nachname"]) ? $_POST["widget-contact-form-nachname"] : null;
    $adresse = isset($_POST["widget-contact-form-adresse"]) ? $_POST["widget-contact-form-adresse"] : null;
    $email $_POST["widget-contact-form-email"];
    $phone = isset($_POST["widget-contact-form-phone"]) ? $_POST["widget-contact-form-phone"] : null;
    $subject = isset($_POST["widget-contact-form-subject"]) ? $_POST["widget-contact-form-subject"] : 'Gewinnspiel';
    $message = isset($_POST["widget-contact-form-message"]) ? $_POST["widget-contact-form-message"] : null;

    $recaptcha_response = isset($_POST["g-recaptcha-response"]) ? $_POST["g-recaptcha-response"] : null;


    if( 
    $_SERVER['REQUEST_METHOD'] == 'POST') {


     if(
    $email != '') {

                    
    //If you don't receive the email, enable and configure these parameters below:

                    //$mail->isSMTP();                                      // Set mailer to use SMTP
                    //$mail->Host = 'mail.yourserver.com';                  // Specify main and backup SMTP servers, example: smtp1.example.com;smtp2.example.com
                    //$mail->SMTPAuth = true;                               // Enable SMTP authentication
                    //$mail->Username = 'SMTP username';                    // SMTP username
                    //$mail->Password = 'SMTP password';                    // SMTP password
                    //$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
                    //$mail->Port = 587;                                    // TCP port to connect to

                     
    $mail->IsHTML(true);                                    // Set email format to HTML
                    
    $mail->CharSet 'UTF-8';

                    
    $mail->From $email;
                    
    $mail->FromName $name;

                    if(
    strpos($to',') !== false){
                        
    $email_addresses explode(','$to);
                        foreach(
    $email_addresses as $email_address) {
                           
    $mail->AddAddress(trim($email_address));
                        }
                     }
                     else {
                         
    $mail->AddAddress($to);
                     }

                    
    $mail->AddReplyTo($email$name);
                    
    $mail->Subject $subject;




                    
    $vorname = isset($vorname) ? "Vorname: $vorname<br><br>" '';
                     
    $nachname = isset($nachname) ? "Nachname: $nachname<br><br>" '';
                    
    $email = isset($email) ? "Email: $email<br><br>" '';
                    
    $phone = isset($phone) ? "Telefon: $phone<br><br>" '';
                     
    $adresse = isset($adresse) ? "Adresse: $adresse<br><br>" '';
                    
    $message = isset($message) ? "Nachricht: $message<br><br>" '';


                    
    $mail->Body $vorname $nachname $email $phone $adresse $message '<br><br><br>Diese Nachricht wurde gesendet von: ' $_SERVER['HTTP_REFERER'];

                   
    // Check if google captch is present
                    
    if(!empty($recaptcha_secret_key)) {

                        
    $ch curl_init();

                        
    curl_setopt_array($ch,[CURLOPT_URL=>'https://www.google.com/recaptcha/api/siteverify',CURLOPT_POST =>true,CURLOPT_POSTFIELDS=>['secret'=> $recaptcha_secret_key,'response'=>$recaptcha_response,'remoteip'=>$_SERVER['REMOTE_ADDR']],CURLOPT_RETURNTRANSFER => true]);

                        
    $response curl_exec($ch);
                        
    curl_close($ch);
                        
    $json json_decode($response);

                        if (
    $json->success !== true ) {
                            
    $response = array ('response'=>'error''message'=> "Captcha is not Valid! Please Try Again.");
                        }else {
                           if(!
    $mail->Send()) {
                                
    $response = array ('response'=>'error''message'=> $mail->ErrorInfo);  
                            }else {
                                
    $response = array ('response'=>'success');  
                            }
                        }
                    }else {
                        if(!
    $mail->Send()) {
                            
    $response = array ('response'=>'error''message'=> $mail->ErrorInfo);  

                        }else {                  
                            
    $response = array ('response'=>'success');  
                        }
                    }

                echo 
    json_encode($response);
    } else {
        
    $response = array ('response'=>'error');     
        echo 
    json_encode($response);
    }

    }
    ?>



    Kann mir hier bitte bitte jemand auf die Sprünge helfen?
    Ich kriegs einfach nicht hin.


    Denise








  • #2
    Dann zeig doch mal, was du bisher versucht hast, damit man dir helfen kann. Aber mal als ersteer Tipp, deinen Select Feldern fehlt das Namen Attribute. Sie werden also nicht zum Server übermittelt.

    Wenn du nur jemanden Suchst, welcher dir das Skript fertig schreibt, dann kannst du hier im Forum ein Job-Anbot erstellen.

    Kommentar


    • #3
      Hallo Zeichen32,
      ich hab es tatsächlich gerade hinbekommen ).
      Frage 1 hatte ja das name-Attribut. Damit hatte ich getestet.
      War einfach zu spät gestern abend.
      Trotzdem vielen Dank für Deine Hilfe.

      Grüße Denise


      Kommentar

      Lädt...
      X