我正在创建一个“忘记密码”页面,用户输入其电子邮件地址,脚本会找到与该电子邮件关联的密码,并将其发送到存储的电子邮件地址。
我认为问题与我的SMTP邮件服务器有关。我使用的WAMP没有,所以我下载了一个免费的。
这是我正在使用的php脚本:
$id = checkEmail($email);
$record = readMemberRecord($id);
$password = @mysql_result($record,0,'cred');
if($password){
$email_subject = "Email Request";
$email_body = "Your password is ".$password.".";
$header = "NinjaMan";
mail($email, $email_subject, $email_body,$header);
$msg = "Your password has been sent to ".$email.".";
}else{
$msg = "Sorry, the email ".$email." wasn't found.";
}
$ msg输出正确,所以我知道代码正在传递邮件功能。
答案 0 :(得分:3)
尝试在$header
中发送正确的“发件人”。
$emailFrom = "admin@yourdomain.com"; // match this to the domain you are sending email from
$email = "example@example.com";
$subject = "Email Request";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Your password is ".$password.".";
mail($email, $subject, $message, $headers);
的详细信息
如果这不起作用,请尝试使用PHPMailer。您可以在代码中配置它,无需编辑php.ini。
我在一些项目中使用它(v 2.0.4,我看到最新的是5.1)并且没有问题。
答案 1 :(得分:0)
尝试使用Google的服务器发送邮件,您可以看到如何执行此操作here
答案 2 :(得分:0)
尝试使用此
//Email information
$to = "garggarima@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a test email message.";
$from = "support@sltechsoft.com";
$headers = "From:" . $from;
$mail=mail($to,$subject,$message,$headers);
if($mail) {
echo "Thanks for mail";
} else {
echo "Mail not Sent";
}
//Email response
echo "Thank you for contacting us!";