php邮件功能无法在线服务器上运行

时间:2014-12-13 08:10:13

标签: php email

我想发送邮件,代码如下。我不明白发生了什么。它适用于localhost,但不适用于实时服务器。

if (isset($_POST['test_mail'])){
                            $to             =   '2606ankit@gmail.com';  //put email address on which mail send
                           $subject     =   "Newsletter";                   //Put subject of mail here
                           $from        =   'ankit@studiokrew.com';     //put email address from 
                           //email body start
                          // $body    .=    file_get_contents('file/'.$filename.'');
                           $body      .= 'anio';
                           // Always set content-type when sending HTML email
                            $headers = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

                            // More headers
                            $headers .= 'From: '.$from. "\r\n";

                            //if you need to send cc mail then uncomment below line and change email address
                            //$headers .= 'Cc: myboss@example.com' . "\r\n";

                         mail($to,$subject,$body,$headers); 

  }

3 个答案:

答案 0 :(得分:1)

 try this..
 <?php  if (isset($_POST['test_mail'])){
   $host=$_SERVER['HTTP_HOST'];
   $replyto="<no-reply >";
   $to ='2606ankit@gmail.com'; 
   $subject = "Newsletter"; 
   $from  = 'ankit@studiokrew.com';
   $headers = "From: \"Invoice\"<noreply@$host>\n";
   $headers .= "Reply-To: ".$replyto."\r\n";
   $headers .= "MIME-Version: 1.0\r\n";
   $headers .= "Content-Type: multipart/mixed; boundary=\"abc"\"\r\n\r\n";
   $headers .= 'From: '.$from. "\r\n";
   $header .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
   $body = "This is a multi-part message in MIME format.\r\n";
   $body .= "Content-type:text/html; charset=iso-8859-1\r\n";
   $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
   $body      .= 'anio';                          
   mail($to,$subject,$body,$headers); 
}

&GT;

答案 1 :(得分:0)

检查服务器上的MTA日志。否则,Web服务器日志的答案就会出现在某处。

答案 2 :(得分:0)

使用不需要任何外部数据的简单mail()脚本进行测试,只是为了确保您的服务器确实可以发送邮件。如果失败,您必须联系服务器管理员寻求帮助。