Ich habe index.html mit der Form:ich nicht E-Mails von Kontaktformular erhalten
<form method="post" action="mail.php">
<div class="col-sm-7">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Comment" rows="5"></textarea>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" type="submit">Send</button>
</div>
</div>
</div>
</form>
und mail.php:
<?php
// Check for header injection
function has_header_injection($str){
return preg_match("/[\r\n]/", $str);
}
if(isset($_POST['submit'])){
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$msg = $_POST['message'];
// Check to see if $name or $email have header injections
if(has_header_injection($name) || has_header_injection ($email)){
die(); //if true kill the script
}
if(!$name || !$email || !$msg){
echo '<h2>All fields required</h2><a href="mail.php" class="button block">Go back and try again</a>';
exit;
}
// Add the recipient email to a variable
$to = "[email protected]";
// Create a subject
$subject = "$name sent you a message via your website";
//Construct the message
$msg = "Name: $name\r\n";
$msg .= "Email: $email\r\n";
$msg .= "Message:\r\n$msg";
$msg = wordwrap($msg, 72);
// Set the mail headers into a variable
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n\r\n";
// Send the email
mail($to, $subject, $msg, $headers)
}
?>
<script language="javascript"> window.location="index.html";</script>
, was im falsch? Ich testete dies auf localhost und auf einer gehosteten Website und das gleiche. Wenn ich mit dem ausgefüllten Formular absende, sende es mich einfach an eine leere Seite mail.php, kein Fehler, mit dem Skript unter PHP schickt es mich zurück zur Hauptseite (das ist bc ich will). Getestet habe ich füge hinzu:
if (mail($to, $subject, $body, $headers)===false) { echo "Not sent!"; } else { echo "Sent!"; }
aber kein Fehler, tut es mir zeigen, dass es gesendet wurde oder auch nicht ... so etwas mache ich falsch? Jemand hat mir gesagt, dass ich mir keine E-Mails schicken kann, also habe ich jemand anderen gebeten, mir eine E-Mail zu schicken ... kein Glück, noch immer keine E-Mail gesendet.
Pls Hilfe im an diese für mehr als 3 Tage stecken bereits: \
'if (isset ($ _ POST ['submit'])) {...}' wird nie passieren; Es ist ein undefinierter Index. –
müssen Sie sendmail auf Ihrem Webserver installieren. –
* "aber kein Fehler" * - das liegt daran, dass Sie nicht nach ihnen suchen. –