Subject = stripslashes($subject);
$mail->From = $mailfrom;
$mail->FromName = $mailfrom;
$mailto_array = explode(",", $mailto);
$mailcc_array = explode(",", $mailcc);
$mailbcc_array = explode(",", $mailbcc);
for ($i = 0; $i < count($mailto_array); $i++)
{
if(trim($mailto_array[$i]) != "")
{
$mail->AddAddress($mailto_array[$i], "");
}
}
for ($i = 0; $i < count($mailcc_array); $i++)
{
if(trim($mailcc_array[$i]) != "")
{
$mail->AddCC($mailcc_array[$i], "");
}
}
for ($i = 0; $i < count($mailbcc_array); $i++)
{
if(trim($mailbcc_array[$i]) != "")
{
$mail->AddBCC($mailbcc_array[$i], "");
}
}
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address (" . $mailfrom . ") is invalid!\n
";
throw new Exception($error);
}
$sender_domain = substr($mailfrom, strpos($mailfrom, '@') + 1);
if (!checkdnsrr($sender_domain, "MX"))
{
if (!(checkdnsrr($sender_domain, "A")) or !(checkdnsrr($sender_domain, "AAAA")))
{
$error .= "No email can be sent to the specified domain (" . $sender_domain . ").\n
";
throw new Exception($error);
}
}
$mail->AddReplyTo($mailfrom);
foreach ($_POST as $key => $value)
{
if (preg_match('/www\.|http:|https:/i', $value))
{
$error .= "URLs are not allowed!\n
";
throw new Exception($error);
break;
}
}
if (!empty($_POST['电子信箱']) && !preg_match("/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i", $_POST['电子信箱']))
{
$error .= "请填写正确电邮地址\n
";
}
if (!empty($error))
{
throw new Exception($error);
}
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
$message .= "Referer : ";
$message .= $_SERVER['SERVER_NAME'];
$message .= $_SERVER['PHP_SELF'];
$message .= $eol;
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
}
}
$mail->CharSet = 'UTF-8';
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if (is_array($_FILES[$key]['name']))
{
$count = count($_FILES[$key]['name']);
for ($file = 0; $file < $count; $file++)
{
if ($_FILES[$key]['error'][$file] == 0)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'][$file], $_FILES[$key]['name'][$file]);
}
}
}
else
{
if ($_FILES[$key]['error'] == 0)
{
$mail->AddAttachment($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
}
}
}
}
$mail->WordWrap = 80;
$mail->Body = $message;
$mail->Send();
header('Location: '.$success_url);
}
catch (Exception $e)
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $e->getMessage(), $errorcode);
echo $errorcode;
}
exit;
}
?>





