联系我们页面无法正常工作
问题描述:
刚刚加入了几分钟前。联系我们页面无法正常工作
我想看看是否有人能告诉我为什么我的联系人页面没有给我发电子邮件。
我的联系人页面here
我没有得到任何错误。如果你输入你的信息,它似乎发送它。它甚至会向您发送您的电子邮件已发送的消息。但我没有收到任何电子邮件。
上面的文档类型我有
的formprocess.php编码这样的[我取出我的电子邮件,以避免垃圾邮件]:
<?php
include('includes/corefuncs.php');
if (function_exists('nukeMagicQuotes')) {
nukeMagicQuotes();
}
// process the email
if (array_key_exists('send', $_POST)) {
$to = '[email protected]'; // use your own email address
$subject = 'Email from your contact form';
// list expected fields
$expected = array('name', 'email', 'comments');
// set required fields
$required = array('name', 'email', 'comments');
// create empty array for any missing fields
$missing = array();
// assume that there is nothing suspect
$suspect = false;
// create a pattern to locate suspect phrases
$pattern = '/Content-Type:|Bcc:|Cc:/i';
// function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
// if the variable is an array, loop through each element
// and pass it recursively back to the same function
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
// if one of the suspect phrases is found, set Boolean to true
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}
// check the $_POST array and any sub-arrays for suspect content
isSuspect($_POST, $pattern, $suspect);
if ($suspect) {
$mailSent = false;
unset($missing);
}
else {
// process the $_POST variables
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
}
// otherwise, assign to a variable of the same name as $key
elseif (in_array($key, $expected)) {
${$key} = $temp;
}
}
}
// validate the email address
if (!empty($email)) {
// regex to ensure no illegal characters in email address
$checkEmail = '/^[^@][email protected][^\s\r\n\'";,@%]+$/';
// reject the email address if it doesn't match
if (!preg_match($checkEmail, $email)) {
array_push($missing, 'email');
}
}
// go ahead only if not suspect and all required fields OK
if (!$suspect && empty($missing)) {
// build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Comments: $comments";
// limit line length to 70 characters
$message = wordwrap($message, 70);
// create additional headers
/*$additionalHeaders = 'From: Frank Juval Studio Site';
if (!empty($email)) {
$additionalHeaders .= "\r\nReply-To: $email";
}*/
// send it
$mailSent = mail($to, $subject, $message, $additionalHeaders);
if ($mailSent) {
// $missing is no longer needed if the email is sent, so unset it
unset($missing);
}
}
}
?>
我不是PHP程序员。我从一个免费提供教程的网站抓取了这段代码。我的专长是HTML/CSS。最终我会进入PHP。
感谢您的帮助提前。
弗兰克
答
尝试用一些简单得多:
mail('[email protected]', 'Subject', 'Message');
如果它被发送,那么脚本可能是问题。如果不是,那么您的主机可能不支持发送电子邮件。
+0
感谢metrobalderas的回复。虽然它似乎没有工作。 是的,脚本是问题。我已经做了一些工作。唯一不正确的是发送实际的消息。它发送所有其他信息(即名称,主题,电子邮件),但不发送邮件正文。 任何想法如何解决这个问题?我将重新发布更新后的PHP代码。 – FrankDraws
答
<?
$destination="mailto:[email protected]";
$name=$_POST['Name'];
$Phone=$_POST['Phone'];
$State=$_POST['State'];
$email=$_POST['Email'];
$mes=$_POST['Message'];
$subject="Message from $name" ;
$mes="Name : $name\n Phone: $Phone\n
Email: $email\n\n Message: $mes\n";
mail($destination,$subject,$mes);
?>
没有先看代码,你是否证实'mail()可以在你的服务器上工作?您可以通过制作一个PHP文件并填写'mail()'参数,然后访问该脚本来调用电子邮件来检查。 – Sampson
是的,我的服务器支持电子邮件。我曾经有一个CMS,但把它放下,以重新设计我的网站。 – FrankDraws