dongqianzhan8325 2012-03-26 11:48
浏览 33
已采纳

如何从shell发送带有php的邮件

I have the following code in sendmail.php:

#!/usr/bin/php
<?php 
$to = "testmail@gmail.com";
$subject = "TestSubject";
$body = "TestBody";
if (mail($to, $subject, $body)){
    echo "Mail Sent";
}else {
    echo "Mail Failed";
}
?>

If I visit the web pathtothefile/sendmail.php it sends the mail OK. but if i make in a shell:

  chmod 755 sendmail.php
  ./sendmail.php

It says "Mail Sent" but nothing is sent. Why is that happening? Thanks

  • 写回答

1条回答 默认 最新

  • dqh1992 2012-03-26 14:45
    关注

    As Tuong Le suggested I would look at your php.ini file. Also after reviewing

    http://php.net/manual/en/function.mail.php

    You may want to check your code once through to make sure you have all the necessary information.

    If I was in your situation I would take out my own code and insert the sample code directly from the php manual to see where your issue might be occurring.

    Try the following just to see if your mail gets sent out?

    <?php
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "
    " .
    'Reply-To: webmaster@example.com' . "
    " .
    'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数