我有一段代码经审批后发送邮件到电子邮件地址。电子邮件未发送。我是否需要在Web服务器上配置某些内容?
function mailpassword($email, $password){
//notify that the password has been changed
mysqli_select_db($connect,"members");
$query = "select email from users where email = '".$email."'";
$mailquery = mysqli_query($connect,$query);
if(!$mailquery)
{
throw new Exception ('The entered email address could not be found');
}
else if($mailquery->num_rows==0)
{
throw new Exception ('The entered email address could not be found');
//username not in database
}
//if no errors, send mail
else
{
$row = $mailquery->fetch_object();
$email = $row->email;
$from = "From : support@example.com \r\n";
$mesg = "Hey,\n\n You requested for a new password. We have generated a completely random password for you, use it to login.\n\n
New Password - ".$password."\r\n
Please change this random password to a password of your choice once you log in. To change your password, click on the Accounts tab present in your dashboard.\r\n
Cheers\r\n
Hap";
if(mail($email, 'Password Change Account Details', $mesg, $from))
{
return true;
echo "great";
}
else
{
echo "Something went wrong";
}
}
$mails = mailpassword();
}
答案 0 :(得分:0)
尝试删除From标题中冒号之前的空格:
$from = "From: support@example.com \r\n"
答案 1 :(得分:0)
电子邮件问题有一个简单的解决方案:使用托管解决方案,确保从您的应用程序发送的所有电子邮件都能通过。还有一些替代方案,例如Amazon和Postmark。我们使用Postmark取得了巨大的成功(虽然没有附属;)
有这个PHP class for Postmark,我有点自豪......: - )
这不是你问题的直接答案,但我希望无论如何它都有帮助!