我遇到了一個簡單的PHP郵件問題。我有這個腳本工作,但它現在不工作,我不明白爲什麼不是我的生活。而是將原始的HTML而不是渲染的模板吐出來。PHP mail()錯誤;我看不到看!
如果有人可以瀏覽並找回我,那就太好了。提前致謝。
<?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 <[email protected]>' . "\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="[email protected]" />
</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>
電子郵件的URL是http://www.digitalpop.co.uk/xmas_email/爲那些誰想要看看它應該是什麼樣子。 – 2009-12-21 17:13:11
你是什麼意思的原始HTML?它是否包含未分析的PHP代碼? – 2009-12-21 17:14:57
是的。它在「MIME-Version:1.0」之後吐出標題,然後是index.html的源代碼。 – 2009-12-21 17:17:24