简单的电子邮件功能不起作用


simple email function not working

我在我的活动站点中编写了这段代码。

$to = "samplmail@gmail.com";
$subject = "sample";
$message = "hiiiiiiiiiii";
$from = "samplmail@yahoo.com";
$headers = "From: " .$from. "'r'n";
$headers .= "Reply-To: ". $to. "'r'n";
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";
$mail = mail($to, $subject, $message, $headers);
if( $mail ) {
   echo "mail sent";
} else {
   echo "mail not sent";
}

但它打印"邮件未发送"。我也没有收到任何电子邮件。请帮我解决这个问题。

你应该考虑使用 https://github.com/Synchro/PHPMailer。

这只是我经常在应用程序中使用的简单示例成功代码:

<?php
include('class/class.phpmailer.php');
$subject = "Your subject here";
$message = "<p>HTML Email message</p>";
$mail = new PHPMailer();
$mail->AddReplyTo("your_email_from@example.com","Your Name");
$mail->SetFrom("your_email_from@example.com","Your Name");
$mail->AddAddress("customer_email@gmail.com", "Customer Name");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
?>

如果使用该代码仍然不起作用,那么您应该向您的托管服务提供商询问此问题。