我尝试在提交表单后向用户发送HTML电子邮件,但未能发送包含PHP mail()
功能的电子邮件。我从最近2个小时开始研究同样的事情。我找不到解决方案。
以下是我的代码,请提出您的建议。
<?php
$replyemail="sales@companyname.com";
if (!isset($_POST['email']))
{
echo "<script language=\"JavaScript\"><!--\n ";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}
function is_forbidden($str,$check_all_patterns = true)
{
$patterns[0] = 'Content-Type:';
$patterns[1] = 'mime-version';
$patterns[2] = 'multipart/mixed';
$patterns[3] = 'Content-Transfer-Encoding';
$patterns[4] = 'to:';
$patterns[5] = 'cc:';
$patterns[6] = 'bcc:';
$forbidden = 0;
for ($i=0; $i<count($patterns); $i++)
{
$forbidden = eregi($patterns[$i], strtolower($str));
if ($forbidden) break;
}
//check for line breaks if checking all patterns
if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str);
if ($forbidden)
{
echo "<font color=red><center><h3>STOP! Message not sent.</font></h3><br><b>
The text you entered is forbidden, it includes one or more of the following:
<br><textarea rows=9 cols=25>";
foreach ($patterns as $key => $value) echo $value."\n";
echo "Error";
exit();
}
else return $str;
}
$email = is_forbidden($_POST["email"]);
$contact = is_forbidden($_POST["contact"]);
$comments = is_forbidden($_POST["comments"]);
$ccemail = "From: $email" . "\r\n" .
"CC: demo@companyname.com";
$mailHeader = "MIME-Version: 1.0\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mailHeader .= "From: " . $email . "\r\n";
$mailHeader .= "Cc: demo@companyname.com\r\n";
$themessage = 'Hello';
mail("$replyemail","Thanks for Register","$themessage","$mailHeader");
?>
答案 0 :(得分:0)
我也被困了一次。我建议你尝试不同的电子邮件地址(我发现邮件只被发送到gmail),如果它不起作用,那么联系你的托管服务(免费托管是不可靠的,只要使用PHP mail()函数关注)。