[PHP 警告:邮件 ():“sendmail_from”未在 php.ini 或自定义 "From:" 中设置 header 丢失
[PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header missing
我正在尝试使用 PHP 的 mail() 函数发送测试邮件。
$to = "****@gourab.me";
$sub = "Php Mail";
$msg = "Test Message From PHP";
mail($to, $sub, $msg, "From: **********@gmail.com");
当我尝试在 phpdbg
中通过 step
调试它时,它显示消息:
[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]
我不明白为什么?
您的 From
header 格式似乎不正确。试试这个:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <info@address.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $body, $headers);
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
?>
兄弟,您似乎在使用自己的 PC/localhost/127.0.0.1 服务器,这就是您无法连接到 SMTP 服务器的原因。您只能使用类似的编码从实时服务器发送邮件并进行一些修改 :) 即添加一个参数 "Header/From".
mail("You@me.com","Answer","Hope You Vote My Answer Up","From: me@you.com");
<?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);
}
}
?>
我正在尝试使用 PHP 的 mail() 函数发送测试邮件。
$to = "****@gourab.me";
$sub = "Php Mail";
$msg = "Test Message From PHP";
mail($to, $sub, $msg, "From: **********@gmail.com");
当我尝试在 phpdbg
中通过 step
调试它时,它显示消息:
[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]
我不明白为什么?
您的 From
header 格式似乎不正确。试试这个:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <info@address.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $body, $headers);
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
?>
兄弟,您似乎在使用自己的 PC/localhost/127.0.0.1 服务器,这就是您无法连接到 SMTP 服务器的原因。您只能使用类似的编码从实时服务器发送邮件并进行一些修改 :) 即添加一个参数 "Header/From".
mail("You@me.com","Answer","Hope You Vote My Answer Up","From: me@you.com");
<?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);
}
}
?>