我想发送一封邮件,代码如下。 我不明白发生了什么.它适用于本地主机,但不适用于实时服务器。
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);
}
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);
}
?>
检查服务器上的 MTA 日志。Web 服务器日志也会在某个地方找到答案。
使用不需要任何外部数据的简单mail()
脚本进行测试,只是为了确保您的服务器确实可以发送邮件。如果失败,则必须联系服务器管理员寻求帮助。