我一直在尝试一些PHP代码,我无法通过以下代码发送邮件。我已经发送了几天,但现在mail()
函数返回true但邮件不在收件人的收件箱中。这是代码:
$to = "test@example.com";
$subject = "Testing Emails";
$emailBody = "Hello";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: Test <no-reply@example.com>" . "\r\n";
$headers .= "Reply-To: no-reply@example.com"."\r\n";
$mail = mail($to,$subject,$emailBody,$headers);
if($mail){
echo 'Successfully sent';
} else {
echo 'Failed to send';
}
注意:我已将所有to
地址替换为原始地址。