邮件函数在php中不起作用
我的邮件功能不工作。我的邮件功能如下:邮件函数在php中不起作用,php,email,Php,Email,我的邮件功能不工作。我的邮件功能如下: function sendmail($from,$to,$sub,$msg) { $subject=$sub; $message=$msg; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= "From: <'.$from.'>
function sendmail($from,$to,$sub,$msg)
{
$subject=$sub;
$message=$msg;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'.$from.'>" . "\r\n";
mail($to,$subject,$message,$headers);
}
函数sendmail($from,$to,$sub,$msg)
{
$subject=$sub;
$message=$msg;
$headers=“MIME版本:1.0”。\r\n”;
$headers.=“内容类型:text/html;字符集=iso-8859-1”。\r\n”;
$headers.=“From:”\r\n”;
邮件($to、$subject、$message、$headers);
}
这在我的其他一些项目中运行良好,但在我的新项目中不起作用。可能是邮件在您的服务器中不起作用。 使用基本邮件功能进行检查,并将其上载到根目录中以测试邮件 testmail.php
<?php
$msg = "This is test mail";
mail("tester@email.com","My subject",$msg);
?>
如果邮件无法工作,请尝试使用经过身份验证的邮件,如。PHP inbuild mail()函数在您的本地主机或不支持smtp服务器的服务器中无法工作。如果你在你的电脑本地运行这个项目,那么这个邮件功能将无法工作。您需要上传到服务器上,然后再试一次,它会工作的
如果您正在服务器上运行此项目,但您的邮件未触发,则可能出现以下情况:
1) 您将它托管在支持PHP但不支持smtp的Windows server中
2) 若服务器是Linux,那个么服务器可能已经禁用了发送邮件。请联系您的服务器
我建议您使用PHPMailer[它通过外部SMTP服务器(如GMail、Hotmail等)发送邮件。试试看
I finally solved the issue. The problem was I had given my gmail id as admin id ( i.e, from address) now i changed it to a mail id from the domain name(say, if the domain name is www.abc.com I gave id as noreply@abc.com) and it works.
现在我知道,在某些情况下,在某些服务器上提供gmail或其他邮件id会起作用,但不会在所有服务器上都起作用。所以在域名中使用邮件id(noreply@abc.com)将解决这个问题。即使gmail id在某些服务器上工作,它仍然会在邮件正文中给出错误消息,或者是垃圾邮件,因此最好使用从域名派生的邮件id,如noreply@abc.com.
谢谢您……您得到的错误是什么?是不是故意在$headers中的最后一行做了,因为我从:“.”\r\n”