发送使用PHP
问题描述:
我有一段代码,经批准发送邮件到电子邮件地址的邮件。电子邮件未被发送。我需要在我的Web服务器上配置什么?发送使用PHP
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 : [email protected] \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();
}
答
有一个简单的解决方案以电子邮件的问题:使用托管的解决方案,可确保您的应用程序发送的所有电子邮件获得通过。有一些替代品,如Amazon和Postmark。我们用邮戳取得了巨大成功(不隶属于虽然外置热交换器;)
有这个PHP class for Postmark说我还挺自豪的... :-)
这不是直接回答你的问题,但我无论如何希望它有帮助!
你可以测试但不带'$ from'场。它在':'和'\ r \ n'之前包含无关的空格(如果它是最后一个/唯一的标题,它也应该省略)。 – mario 2011-03-12 14:56:03
@mario - 好点,注意。我将来会这样做 – 2011-03-12 15:08:02