[PHP 警告:mail(): "sendmail_from" 未在 php.ini 中设置或自定义 "From:" 标头丢失
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28026932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
[PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header missing
提问by Ikari
I am trying to use PHP's mail() function to send a test mail.
我正在尝试使用 PHP 的 mail() 函数发送测试邮件。
$to = "****@gourab.me";
$sub = "Php Mail";
$msg = "Test Message From PHP";
mail($to, $sub, $msg, "From: **********@gmail.com");
When I try to debug it through step
in phpdbg
, it shows the message:
当我尝试通过step
in调试它时phpdbg
,它显示以下消息:
[PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header
missing in C:/xampp/htdocs/tinyProj/mail.php on line 4]
I cannot understand why?
我不明白为什么?
回答by fillobotto
It seems your From
header is not correctly formatted. Try this instead:
看来您的From
标题格式不正确。试试这个:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <[email protected]>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $body, $headers);
回答by Mohammad Hani
Bro it seems that you're using you own PC/localhost/127.0.0.1 server that's why you can't connect to SMTP server. You can only send mail from live server using similar coding with some amendments :) i.e. add one parameter "Header/From".
兄弟,您似乎正在使用自己的 PC/localhost/127.0.0.1 服务器,这就是您无法连接到 SMTP 服务器的原因。您只能使用类似的编码和一些修改从实时服务器发送邮件:) 即添加一个参数“标题/发件人”。
mail("[email protected]","Answer","Hope You Vote My Answer Up","From: [email protected]");
回答by YUSUPH SAFARI
<?php
if(isset($_POST['send'])){
$from = $_POST['femail'];
$phoneno = $_POST['phoneno'];
$message = $_POST['message'];
$carrier = $_POST['carrier'];
if(empty($from)){
echo("enter the email");
exit();
}
else if(empty($phoneno)){
echo("enter the phone no");
exit();
}
elseif(empty($carrier)){
echo("enter the specific carrier");
exit();
}
else if(empty($message)){
echo("enter the message");
exit();
}
else{
$message = wordwrap($message, 70);
$header = $from;
$subject = 'from submission';
$to = $phoneno.'@'.$carrier;
$result = mail($to, $subject, $message, $header);
echo("message sent to".$to);
}
}
?>
回答by Whirlwind
<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>