当用户忘记密码登录我的网站时,我希望通过电子邮件发送新密码。除非是Gmail地址,否则电子邮件无法发送。任何人都可以解释问题是什么吗?
<?php
$email_address=$_POST['email_to'];
$tbl_name=user;
$query="SELECT * FROM user WHERE email = '$email_address'";
$st=mysql_query($query);
$recs=mysql_num_rows($st);
if ($recs == 0)
{
echo "<center><font face='Verdana' size='2' color=red><b>No Password</b><br> Sorry Your address is not there in our database . You can signup and login to use our site. <BR><BR> </center>";
exit;
}
if ($recs == 1){
function makeRandomPassword()
{
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7)
{
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
$sql = mysql_query("UPDATE user SET password='$db_password',display_pass='$random_password' WHERE email='$email_address'");
echo "New Password has been send to your email.";
echo "<a href='index.php'>Back</a>";
//------- SEND MAIL FORM --------
$to=$email_address;
$subject="Your password here";
$header="from: Admin Ayam Kampung Lingnan <your email>";
// Your message
$messages= "Password Anda untuk login ke website Lingnan \r\n";
$messages.="Password Anda Adalah: $random_password \r\n";
$messages.="Mohon untuk tidak di balas, karena ini adalah email otomatis \r\n";
// send email
$sentmail = mail($to,$subject,$messages,$header);
}
}
?>
答案 0 :(得分:0)
您的标题行无效。
如果From标头包含名称且该名称包含空格,则应引用该名称。
尝试:
$header="From: \"Admin Ayam Kampung Lingnan\" <emailaddress@example.com>";
虽然,您应该考虑从任何不是您的邮件服务器的本地域的电子邮件地址发送,很可能在某个时候被阻止,或者至少更有可能被标记为垃圾邮件。