dryl34156 2015-06-05 06:47
浏览 8

php中的邮件功能不发送头文件

I brought a shared sever, and got a little storage space. When i run my web site, the mail function works perfectly. Mail has been sent with subject and message to all receivers. But the mail which is sent mentioned "From : ". Headers what i included are not working. I want to send with my headers Eg:Form: mymail@mysite.com . How can i do it?

<?php
$output="";
if(isset($_POST['submit']) && !empty($_POST['message']))
{
    $sub=$_POST['subject'];
    $msg=$_POST['message'];
    $sql = "select email from login where status='client'";
    $query = mysqli_query($con,$sql);

    $to=array();

    while($row = mysqli_fetch_array($query))
    {
        $to[] = $row['email'];
        $parts = implode(',',$to);
        $headers = 'From: mymail@mysiet.com;';
        $headers .= 'MIME-Version: 1.0' . "
";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
        $subject = $sub;
        $content = $msg;    
    }

    if(mail($parts,$subject,$content,$headers))
    {
        $output="mail sent";
    }
    else
    {
        $output="Error in connection, Mail could not be sent. Please try again";
    }

}
?>
  • 写回答

2条回答 默认 最新

  • drmg17928 2015-06-05 07:03
    关注

    You need to manually specify the headers, this is the function I use and it delivers to pretty much every provider beautifully. The headers you want are From: and Reply-To: and I also advise the X-Mailer follows what is seen here, I found it years ago via SO as well.

    <?php
        $to      = "user@anotherdomain.com";                                
        $headers = 'From: My Name <email@domain.com.au>' . "
    " .
                   'Reply-To: My Name <email2@domain.com.au>' . "
    " .
                   'X-Mailer: PHP/' . phpversion() . "
    " .
                   'Content-type: text/html; charset=iso-8859-1';
        $subject = "My subject line here";
        $message = 'Message HTML and Content Here.';
    
        if(mail($to, $subject, $message, $headers)){
            // Success Here
        }else{
            // Failed Here
        }
    ?>
    

    I am not 100% certain it will work for you as I am on a dedicated machine, having said that - I do use it on multiple domains and have never messed with my Apache or php configuration in relation to mail settings.

    Read More about the Mail function in PHP: http://php.net/manual/en/function.mail.php

    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误