2016-04-08 3 views
-1

Ich habe meine eigene mail.php bereits gemacht, aber ich habe über PHPMailer gelernt und wollte es auf meinem Formular für meine neue Website implementieren in Entwicklung. Jedes Mal, wenn ich es teste, indem ich Informationen eintrage und auf "Senden" klicke, bekomme ich einen internen Serverfehler und erkläre nicht wirklich warum, aber vielleicht hat es etwas mit meinem Header zu tun.Mein Kontaktformular gibt mir einen internen Serverfehler (500) nach dem Testen/PHPMailer

my site/page for reference

Mein Code:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<form action="php/mail.php" method="POST"> 
 
    <div class="form-group"> 
 
    <input type="text" class="form-control" id="name" placeholder="Full Name" required> 
 
    </div> 
 
    <div class="form-group"> 
 
    <input type="email" class="form-control" id="email" placeholder="Email Address" required> 
 
    <small class="text-muted">I will never share your email with anyone. Pinky swear.</small> 
 
    </div> 
 
    <div class="form-group"> 
 
    <input type="phone" class="form-control" id="phone" placeholder="Phone Number" required> 
 
    </div> 
 
    <div class="form-group"> 
 
    <input type="text" class="form-control" id="company" placeholder="Company (optional)"> 
 
    </div> 
 

 
    <div class="form-group"> 
 
    <div class="radio"> 
 
     <label> 
 
     <input type="radio" name="radio" id="optionsRadios1" value="Project" checked>Project&nbsp;&nbsp; 
 
     </label> 
 
    </div> 
 
    <div class="radio"> 
 
     <label> 
 
     <input type="radio" name="radio" id="optionsRadios2" value="Collab">Collaboration&nbsp;&nbsp; 
 
     </label> 
 
    </div> 
 
    <div class="radio"> 
 
     <label> 
 
     <input type="radio" name="radio" id="optionsRadios3" value="Other">Other&nbsp;&nbsp; 
 
     </label> 
 
    </div> 
 
    </div> 
 

 
    <div class="form-group"> 
 
    <textarea class="form-control" id="message" rows="4" placeholder="What do you need?" required></textarea> 
 
    </div> 
 
    <button class="btn btn-primary" style="float: right;" type="submit">Send Away!</button> 
 
</form>

Hier ist meine php

<?php 
 

 
//gather all form fields 
 
$name = mysqli_real_escape_string($db, $_POST['name']); 
 
$email = mysqli_real_escape_string($db, $_POST['email']); 
 
$phone = mysqli_real_escape_string($db, $_POST['phone']); 
 
$company = mysqli_real_escape_string($db, $_POST['company']); 
 
$radio = mysqli_real_escape_string($db, $_POST['radio']); \t 
 
$message = mysqli_real_escape_string($db, $_POST['message']); 
 

 
if($name == "" || $email == "" || $phone == "" || $company == "" || $radio == "" || $message == ""){ 
 
\t \t //this could load a modal or some type of error pop up 
 
\t \t echo '<div class="alert alert-danger">The form submission is missing values.</div>'; 
 
     exit(); 
 
\t } 
 
\t else { 
 
\t \t 
 
\t //include autoload 
 
\t require 'php/PHPMailerAutoload.php'; 
 
\t $mail = new PHPMailer; 
 

 
\t $mail->isMail();          // Set mailer to use SMTP 
 
\t 
 
\t $mail->setFrom('[email protected]', 'Mailer'); 
 
\t $mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
 
\t 
 
\t $mail->isHTML(true);         // Set email format to HTML 
 
\t 
 
\t $mail->Subject = 'Here is the subject'; 
 
\t $mail->Body = ' 
 
\t \t <!doctype html> 
 
\t \t <html> 
 
\t \t <head> 
 
\t \t <link rel="stylesheet" href="" type="text/css" media="screen, projection" /> 
 
\t \t <style> 
 
\t \t h1 { font-size: 14px; } 
 
\t \t body {font-family: helvetica neue, arial;} 
 
\t \t </style> 
 
\t \t </head> 
 
\t \t <body> 
 
\t \t 
 
\t \t <table style="width: 600px; padding: 12px;" align="center"> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><img src="img/form.jpg"></td> 
 
\t \t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><strong>Full Name:</strong> '.$name.'</td> 
 
\t \t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><strong>Email Address:</strong> '.$email.'</td> 
 
\t \t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><strong>Phone Number:</strong> '.$phone.'</td> 
 
\t \t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><strong>Company:</strong> '.$company.'</td> 
 
\t \t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><strong>What do you want?:</strong> '.$radio.'</td> 
 
\t \t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t \t <td><strong>What do you need?:</strong> '.$message.'</td> 
 
\t \t \t </tr> 
 
\t \t </table> 
 
\t \t 
 
\t \t </body> 
 
\t \t </html> \t \t \t 
 
\t 
 
\t '; 
 
\t 
 
\t if(!$mail->send()) { 
 
\t \t echo 'Message could not be sent.'; 
 
\t \t echo 'Mailer Error: ' . $mail->ErrorInfo; 
 
\t } else { 
 
\t \t header('http://www.scratchmediaohio.com/twentysixteen'); 
 
\t } \t 
 
\t \t 
 
} 
 
?>

Antwort

0

Sie haben nicht das "name" -Attribut für einige Ihrer Eingaben - daher sind sie nicht Teil des $ _POST-Arrays und daher nicht für Ihr Mail-Skript vorhanden. Name, E-Mail, Telefon und Unternehmen - der einzige, der sie ist die Radio-Auswahl hat:

<input type="text" class="form-control" id="name" placeholder="Full Name" required> 

sollte

<input type="text" class="form-control" name="name" id="name" placeholder="Full Name" required> 

für Ihre Eingaben sein. Ich würde auch mehr Validierung für Ihre Eingaben vorschlagen als Sie derzeit haben.

+0

Natürlich würde ich etwas so offensichtlich vergessen. Ich fügte diese hinzu, aber ich bekomme immer noch den Serverfehler. –

+0

Sie haben ... header ('http://www.scratchmediaohio.com/twentysixteen'); ... aber sollte das nicht sein ... header ("Location: http://www.scratchmediaohio.com/ twentyixteen "); ... und dann brauchst du vielleicht auch eine Erweiterung wie .php – gavgrif

+0

Ich habe diesen Fehler bemerkt und es header (" Location: http://www.scratchmediaohio.com/twentysixteen/contact.php "); aber ich bekomme immer noch den 500 Fehler. Wenn ich die Anzeigefehler einschalte, bekomme ich auch nichts, was merkwürdig ist. –

Verwandte Themen