我的这部分代码会向雅虎发送邮件,但不会向Gmail发送邮件。我还提到了很多相关的常见问题解答'关于PHP mail()
的文档和文档,但那些对我来说没有用。
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(!empty($_POST['submit']))
{
$to = $_POST['email'];
$subject = 'Annual Report';
$message = $_POST['template'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: from@example.com" . "\r\n";
$headers .= "Reply-To: replyto@example.com" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$headers .= "X-Priority: 1" . "\r\n";
$retval = mail($to,$subject,$message,$headers);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
}
else
{
echo "empty";
}
}