I have index.html with the form :
<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>
and 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 = "minusemp@gmail.com";
// 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>
What im doing wrong? I tested this on localhost and on a hosted site and the same. When i submit with the form completed it just send me to a blank page mail.php, no error, with the script below php it sends me back to the main page (thats bc i want to). i tested adding:
if (mail($to, $subject, $body, $headers)===false) {
echo "Not sent!";
} else {
echo "Sent!";
}
but no error, it doesnt show me that it was sent or not either... so what am i doing wrong? Someone told me that i cant send myself emails so i put someone else to send an email for me... no luck, still no email sent.
Pls help im stuck at this for more than 3 days already :\
This is the body of an email
'; if($m->send()){ echo 'Email sent.'; }else { echo $m->ErrorInfo; }` – minus emp Jul 28 '16 at 07:26