我对以下代码有一点问题。当我单击“发送”时,它显示“PHP 警告:mail() [function.mail]:“sendmail_from”未在 php.ini 中设置或自定义“发件人:”标头在 C:** * .com**\mail中丢失.php 在第 21 行"
这是 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);
}
});
}
和 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>";
}
?>
提到的行是“if(mail($to,$message,$headers)){”但我不明白这个错误。
我在另一个网站(另一个域)上使用相同的代码,它运行没有问题。