使用 PHP mail() 函数时遇到问题。它根本不会发送。
我的如下:
//email them new password
$recipient = $actual_email; //recipient
$subject = "Reset Password"; //subject = reason for contacting
// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: Website <do-not-reply-reset@domain.co.nz>\r\n"; //headerfields
$mail_body = "
<html>
<head>
<title>Reset Password</title>
</head>
<body>
<h2>Reset Password</h2>
<p>Hello $actual_email<br />
You recently asked to reset your password.</p>
<p>Your reset password is below:<br />
<br />
<b>$string</b></p>
<br />
<p>It is recommended you copy and paste this password into the login page, and change your password under settings, then delete this email.</p>
<p>If you did not request this change of password, it is recommended you login and change your password immediately, and get in contact with us.</p>
<p>Thank you,<br />
The Team
<br />
NOTE:<br />
Please do not reply to this message, which was sent from an unmonitored e-mail address. Mail sent to this address cannot be answered.</p>
</body>
</html>";
//send mail
if(mail($recipient, $subject, $mail_body, $headers)){ //mail command
header('Location: index.php?success=yes');
exit;
} else {
$error_message = "<div class='error'>
<img src='http://resources.domain.co.nz/backgrounds/icon_error.png' class='messageimg' />
<h4>Error - Recovery Error</h4>
<p>There was an error sending a recovery password. If the problem persists, please contact us directly.</p>
</div>";
}
我确保 sendmail 安装在 UNIX 的默认位置,并且它在 PHP.ini 中正确引用它。
我以前使用过相同的代码,没有任何问题,所以我认为它是服务器端的东西?
任何帮助表示赞赏。