我的邮件功能在在线服务器上。它工作正常。但是不是现在。我很困惑为什么它已停止发送邮件。它显示发送电子邮件的消息,但收件箱中未收到任何电子邮件。
这是我的PHP代码:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "From: " . $email . "\n"; //from address
$to = ""; //my mail id
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$subject = "Test mail";
$body = '<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>"."<h3>"."Hello Test,."</h3>".
</title>
</head>
<body><p></p>
<p style="color: #00CC66; font-weight:600; font-style:italic; font-size:14px; float:left; margin-left:7px;">You have received an inquiry from your website. Please review the contact information below.
:</p>';
if (mail($to, $subject, $body, $headers)) {
?>
<h3 style="color:#d96922; font-weight:bold; height:0px; margin-top:1px;">Thank You For Contacting us!!</h3>
<?php
} else {
print_r(error_get_last());
}
}
它出了什么问题?请帮我找出解决方案。还帮我回应错误?
答案 0 :(得分:8)
我试一试,用\r\n
结束每一行,并添加一个 To 标题(看似多余)。此外,在标题中声明charset=utf-8
应该足够了。如果没有,请确保它匹配(此时存在不匹配)。
<?php
$subject = "Test mail";
$to_email = "to@example.com";
$to_fullname = "John Doe";
$from_email = "from@example.com";
$from_fullname = "Jane Doe";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
// Additional headers
// This might look redundant but some services REALLY favor it being there.
$headers .= "To: $to_fullname <$to_email>\r\n";
$headers .= "From: $from_fullname <$from_email>\r\n";
$message = "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\r\n
<head>\r\n
<title>Hello Test</title>\r\n
</head>\r\n
<body>\r\n
<p></p>\r\n
<p style=\"color: #00CC66; font-weight:600; font-style: italic; font-size:14px; float:left; margin-left:7px;\">You have received an inquiry from your website. Please review the contact information below.</p>\r\n
</body>\r\n
</html>";
if (!mail($to_email, $subject, $message, $headers)) {
print_r(error_get_last());
}
else { ?>
<h3 style="color:#d96922; font-weight:bold; height:0px; margin-top:1px;">Thank You For Contacting us!!</h3>
<?php
}
?>
我也会用这样的东西替换第一行,以避免通知/错误:
if ($_POST && isset($_POST['submit']) && isset($_POST['name']) && isset($_POST['email']) && !empty($_POST['name']) && !empty($_POST['email'])) {
答案 1 :(得分:1)
使用godadday服务器可以正常工作,但是在bigrock服务器上,直到我们没有创建响应邮件(来自cpanel的注册邮件)后,它才能正常工作。登录到big rock提供的cpanel,向下滚动以注册邮件ID。创建该邮件ID,例如no-reply@your-domain.com。
一旦您创建了该邮件ID,该邮件功能将开始工作,请等待10-30分钟。
了解更多详情,read this article
答案 2 :(得分:0)
使用邮件邮寄有两种方法
PHP邮件功能mail()
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
参考mail
link:using php mailer
解决的例子:mail with attachment:
答案 3 :(得分:-1)
也遇到了类似的挑战,但最终我的代码中没有错误,我错过了在cpanel上创建电子邮件实际发送的内容。很容易错过,但会让您感到沮丧