[英]E-mails not getting sent
I have a contact form, but the messages are not sending to the email I have declared. 我有一个联系表,但是消息没有发送到我声明的电子邮件中。 This is the submit.php
file: 这是submit.php
文件:
<?php
/* config start */
$emailAddress = 'xxxxxxx@hotmail.com';
/* config end */
require "../php/class.phpmailer.php";
session_name("fancyform");
session_start();
foreach($_POST as $k => $v)
{
if(ini_get('magic_quotes_gpc'))
$_POST[$k] = stripslashes($_POST[$k]);
$_POST[$k] = htmlspecialchars(strip_tags($_POST[$k]));
}
$err = array();
if(!checkLen('name'))
$err[] = 'The name field is too short or empty!';
if(!checkLen('email'))
$err[] = 'The email field is too short or empty!';
elseif(!checkEmail($_POST['email']))
$err[] = 'Your email is not valid!';
if(!checkLen('subject'))
$err[] = 'You have not selected a subject!';
if(!checkLen('message'))
$err[] = 'The message field is too short or empty!';
if((int)$_POST['captcha'] != $_SESSION['expect'])
$err[] = 'The captcha code is wrong!';
if(count($err))
{
if($_POST['ajax'])
{
echo '-1';
}
else if($_SERVER['HTTP_REFERER'])
{
$_SESSION['errStr'] = implode('<br />', $err);
$_SESSION['post'] = $_POST;
header('Location: '.$_SERVER['HTTP_REFERER']);
}
exit;
}
$msg =
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />
Message:<br /><br />
'.nl2br($_POST['message']).'
';
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";
$mail->MsgHTML($msg);
$mail->Send();
unset($_SESSION['post']);
if($_POST['ajax'])
{
echo '1';
}
else
{
$_SESSION['sent'] = 1;
if($_SERVER['HTTP_REFERER'])
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}
function checkLen($str, $len = 2)
{
return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]), "utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
?>
If submit.php
is opened in a browser, I get the following error message: 如果在浏览器中打开submit.php
则会收到以下错误消息:
Warning : require(../php/class.phpmailer.php) [function.require]: failed to open stream: No such file or directory in /home/content/96/9227096/html/submit.php on line 10 警告 :require(../ php / class.phpmailer.php)[function.require]:无法打开流:在第10行的/home/content/96/9227096/html/submit.php中没有此类文件或目录
Fatal error : require() [function.require]: Failed opening required '../php/class.phpmailer.php' (include_path='.:/usr/local/php5_3/lib/php') in /home/content/96/9227096/html/submit.php on line 10 致命错误 :require()[function.require]:无法在/ home / content中打开所需的'../php/class.phpmailer.php'(include_path ='。:/ usr / local / php5_3 / lib / php') /96/9227096/html/submit.php ,第10行
I was also told by my hosting server that I might need to add the following relay server in my code:(but I don't know where) relay-hosting.secureserver.net
托管服务器还告诉我,我可能需要在代码中添加以下中继服务器:(但我不知道在哪里) relay-hosting.secureserver.net
The statement require "../php/class.phpmailer.php";
该语句require "../php/class.phpmailer.php";
means that the ../php/class.phpmailer.php
file will be loaded and that if it can't be loaded then the script will terminate. 表示将加载../php/class.phpmailer.php
文件,如果无法加载,则脚本将终止。
It is unable to load that script. 无法加载该脚本。 That could be for any of a number of reasons. 这可能是出于多种原因。 Maybe it's not there. 也许不在那里。 Maybe the path you provided is wrong. 也许您提供的路径是错误的。 Maybe it's a file permission issue. 可能是文件权限问题。 You'll have to figure that part out. 您必须弄清楚那部分。
But since it can't load it, the script terminates with the error message. 但是由于无法加载,该脚本会终止并显示错误消息。
I have encounter similiar problems on some hosting providers. 我在某些托管服务提供商上遇到了类似的问题。 Even if the path was good require did not include file and terminated whole script. 即使路径良好也要求不包含文件并终止整个脚本。 You could write there a real path to your file, and maybe that will help. 您可以在其中写入文件的真实路径,也许会有所帮助。 Since this problem I started to use 由于这个问题,我开始使用
require(getcwd().'actual/path/relevant/to/index.php');
and starder to write apps in one class, similiar to Java or C# desktop apps. 并愿意编写一类类似于Java或C#桌面应用程序的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.