我遇到了一个简单的PHP邮件问题。我已经有了这个脚本工作,但它现在不起作用,我无法看到我的生活为什么不。它反而是吐出原始HTML而不是渲染模板。
如果有人可以浏览并回复我,那就太棒了。提前谢谢。
<?php
if (isset($_POST['send']))
{
// explode the email addresses
$emails = explode(',', strtolower($_POST['to']));
// validate each email address
foreach ($emails as $id => $email) {
if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL)) {
die($email . ' is not a valid email address');
}
}
// all is good, let's send the emails out
$subject = 'Digital Pop Christmas Email';
$message = file_get_contents('index.html');
// loop through each recipient
foreach ($emails as $email) {
$to = $email;
$subject = 'Merry Christmas from Digital Pop';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $email . "\r\n";
$headers .= 'From: Digital Pop <info@digitalpop.co.uk>' . "\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Email successfully sent to $email";
} else {
echo "Error sending email to $email";
}
echo "<br />\r\n";
}
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>PHP Mailer</title>
<meta http-equiv="author" content="martin@digitalpop.co.uk" />
</head>
<body>
<p>Send the <a href="./">Digital Pop Christmas Email</a>.</p>
<form action="?" method="post">
<fieldset>
<div><label for="to">To:</label> <small>(separate email addresses with commas)</small></div>
<div><textarea name="to" id="to" cols="50" rows="8"></textarea></div>
<div><input type="submit" name="send" value="Send" /></div>
</fieldset>
</form>
</body>
</html>
答案 0 :(得分:0)
在极少数情况下,由于邮件服务器配置错误,您只需要\ n而不是\ r \ n 试试吧。
答案 1 :(得分:0)
我复制了你的代码(php文件和index.html)并给我发了一封漂亮的圣诞快乐邮件:) 它对我来说就像一个魅力,所以问题出在你的服务器配置或你的邮件客户端(我使用GMail)。希望它有所帮助。
答案 2 :(得分:0)
你检查过邮件日志了吗? (通常在/var/log/mail.log中)。如果您在短时间内发送过多电子邮件(Gmail可能会发生),您可能会被暂时屏蔽。