2014-12-13 148 views
0

我想发送邮件的代码如下。我不明白他们正在发生。它适用于本地主机,但不适用于活动服务器。php邮件功能不能在线服务器上工作

if (isset($_POST['test_mail'])){ 
          $to    = '[email protected]'; //put email address on which mail send 
          $subject  = "Newsletter";     //Put subject of mail here 
          $from  = '[email protected]';  //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: [email protected]' . "\r\n"; 

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

    } 
+0

您的邮件服务器没有配置或配置错误的php.ini。检查日志。 – 2014-12-13 08:13:03

回答

0

检查你的server.also web服务器上的MTA日志,答案将在那里。

0

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

1
try this.. 
<?php if (isset($_POST['test_mail'])){ 
    $host=$_SERVER['HTTP_HOST']; 
    $replyto="<no-reply >"; 
    $to ='[email protected]'; 
    $subject = "Newsletter"; 
    $from = '[email protected]'; 
    $headers = "From: \"Invoice\"<[email protected]$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); 
} 

?>

相关问题