I have a little problem with the following code. When I click “Send” it says “PHP Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:***.com**\mail.php on line 21″
This is the jQuery:
$(document).ready(function(){
$("#send").click(function(){
var valid = '';
var isr = ' requested.</h6>';
var name = $("#name").val();
var mail = $("#email").val();
var messaggio = $("#message").val();
if (name.length<1) {
valid += '<h6>A valid name is'+isr;
}
if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<h6>A valid e-mail address is'+isr;
}
if (valid!='') {
$("#re").fadeIn("slow");
$("#re").html("<h6><b>Error:</b></h6>"+valid);
$("#re").css("background-color","#ffc0c0");
}
else {
var datastr ='name=' + name + '&mail=' + mail + '&messaggio=' + encodeURIComponent(messaggio);
$("#re").css("display", "block");
$("#re").css("background-color","#FFFFA0");
$("#re").html("<h6>Sending..</h6>");
$("#re").fadeIn("slow");
setTimeout("send('"+datastr+"')",2000);
}
return false;
});
});
function send(datastr){
$.ajax({
type: "POST",
url: "mail.php",
data: datastr,
cache: false,
success: function(html){
$("#re").fadeIn("slow");
$("#re").html(html);
$("#re").css("background-color","#e1ffc0");
setTimeout('$("#re").fadeOut("slow")',2000);
}
});
}
And the PHP
<?php
$mail = $_POST['mail'];
$name = $_POST['name'];
$text = $_POST['messaggio'];
$ip = $_SERVER['REMOTE_ADDR'];
$to = "admin@****.com";
$message = "E-mail received from: ".$name.", ".$mail.".<br />";
$message .= "Messaggio: <br />".$text."<br /><br />";
$message .= "IP: ".$ip."<br />";
$headers = "From: $mail \n";
$headers .= "Reply-To: $mail \n";
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 \n";
if(mail($to, $message, $headers)){
echo "<h6>Message sent.</h6>";
}
else{
echo "<h6>Ops! We've got a problem! :(</h6>";
}
?>
The mentioned line is “if(mail($to, $message, $headers)){” but I don’t understand the error.
I am using the same code on another website (another domain also) and it runs without problems.
Have you checked the SMTP Settings in PHP.INI?
Set this in your code or in your php.ini:
And if you are sending through a different port than 25, you can also override the default: