【问题标题】:[PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header missing[PHP 警告:mail():“sendmail_from”未在 php.ini 中设置或自定义“发件人:”标头丢失
【发布时间】:2015-03-17 14:16:01
【问题描述】:

我正在尝试使用 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]

我不明白为什么?

【问题讨论】:

  • Bulk,这个问题读起来很清楚,“我不明白为什么?还有其他人吗?”

标签: php email


【解决方案1】:

您的From 标头格式似乎不正确。试试这个:

$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);

【讨论】:

  • 我试过了,但现在 phpdbg 显示 [PHP Warning: mail(): Failed to connect to mailserver at localhost port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
  • 您是在实时服务器上还是只是在您的 PC 上?
  • 我在我的电脑上使用 XAMPP
  • 问题是,sendmail/postfix 服务没有运行
  • 这不是主题,你应该打开不同的问题。在共享/专用服务器或虚拟机或其他任何设备上尝试代码并查看它是否有效。
【解决方案2】:

兄弟,您似乎正在使用自己的 PC/localhost/127.0.0.1 服务器,这就是您无法连接到 SMTP 服务器的原因。您只能使用类似的编码从实时服务器发送邮件并进行一些修改:) 即添加一个参数“Header/From”。

mail("You@me.com","Answer","Hope You Vote My Answer Up","From: me@you.com");

【讨论】:

    【解决方案3】:
    <?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);
    ?>
    

    【讨论】:

      【解决方案4】:
      <?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);
      
        }
      
        }
      ?>
      

      【讨论】:

      • 亲爱的 Yusuph,在回答这类问题时,您应该尽量直接一些,问题说它收到一条错误消息,但代码似乎没问题。
      猜你喜欢
      • 2020-04-05
      • 2022-07-15
      • 2022-07-16
      • 2013-10-10
      • 2013-07-27
      • 1970-01-01
      • 2010-10-11
      • 2016-08-28
      • 2022-12-19
      相关资源
      最近更新 更多