0

我已经在我的实时站点中编写了这段代码。

$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";
}

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

4

1 回答 1

2

您应该考虑使用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();
?>

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

于 2013-10-08T06:42:50.283 回答