【问题标题】:Not receiving mail from php contact form - Namecheap answer未收到来自 php 联系表的邮件 - Namecheap answer
【发布时间】:2014-02-18 22:06:36
【问题描述】:

我只是在创建我的网站,并没有关于编写代码的主要知识。 我已经在网络中创建了一个连接到 php 以发送电子邮件的联系表单。我曾经在一家 x 托管公司使用过它,但现在我在 Namecheap 公司,无法接收从联系表发送的邮件。我已经向 Namecheap 支持团队提出了这个问题,但我不明白如何将答案应用到我当前的表格中。请告诉我如何让它工作。

提前致谢...这是我发送给支持人员的消息、html-php 代码和支持人员答复。

--

我正在使用 namecheap 域名和主机建立一个站点并创建了一个电子邮件:creative@mydomain.co

并在我的网站中的 php POST 中有一个联系表格,允许访问者与我联系,将表格发送到我的电子邮件帐户(creative@mydomain.co 和 creative@gmail.com)

问题是我没有收到网站发送的表格,我的 namecheap 邮件和 gmail 帐户都没有。

我在另一个主机域中使用了相同的表单并且工作正常,但它不适用于 namecheap。我想知道我可以做些什么来使它正常工作,因为每次有人填写表格并提交它时,我都会在 creative@mydomain.co 中收到以下电子邮件作为垃圾邮件:

A message that you sent was rejected by the local scanning code that
checks incoming messages on this system. The following error was given:

"Relaying not permitted"

------ This is a copy of your message, including all the headers. ------

Received: from rdxvimy by server89.web-hosting.com with local (Exim 4.80.1)
(envelope-from <rdxvimy@server89.web-hosting.com>)
id 1W6Pqa-025POLD-IT
for creative@gmail.com; Thu, 23 Jan 2014 14:21:52 -0500
To: creative@gmail.com
Subject: Contact: Richard P
From: creative@gmail.com
Message-Id: <E1W6Pqa-025POLD-IT@server89.web-hosting.com>
Sender: <rdxvimy@server89.web-hosting.com>
Date: Thu, 23 Jan 2014 14:21:52 -0500

Name: Richard P

Tel: 2282922 

Mail: creative@gmail.com 

City: N/A

Activity: Designer

Comment: How can you help me to increase my brand? 

--

我没有在我的 creative@mydomain.co 帐户中收到这个,而是在 _mainaccount@mydomain.co 中收到的

我把html和php代码发给你:

HTML

<div id="contact">
<div id="contactArea" style="height: 0px;">
<form action="contactForm.php" method="post">


<div id="info_contact">
<label for="author"></label>
<input id="name" class="rounded" type="text" aria-required="true" tabindex="1" size="12" onFocus="if (this.value=='Name:') this.value='';" value="Nombre:" name="name">
<label for="tel"></label>
<input id="tel" class="rounded" style="width:200px;" type="text" aria-required="true" tabindex="2" size="22" onFocus="if (this.value=='Tel:') this.value='';" value="Tel:" name="tel">
<label for="email"></label>
<input id="email" class="rounded" style="width:270px; margin-left:12px;" type="text" aria-required="true" tabindex="3" size="22" onFocus="if (this.value=='E-mail:') this.value='';" value="Mail:" name="email">

<label for="city"></label>
<input id="city" class="rounded" style="width:200px;" type="text" aria-required="true" tabindex="4" size="22" onFocus="if (this.value=='City:') this.value='';" value="City:" name="city">
<label for="actividad"></label>
<input id="actividad" class="rounded" style="width:270px; margin-left:12px;" type="text" aria-required="true" tabindex="5" size="22" onFocus="if (this.value=='Activity:') this.value='';" value="Activity:" name="activity">
</div>

<div id="comment">
<label for="comment"></label>
<textarea id="message" class="rounded" onfocus="clearDefault(this)" tabindex="6" rows="3" cols="2" name="message" style="resize: none;">How can you help me to increase my brand?</textarea>
<input id="submit" class="envoie" value="Send" type="submit" tabindex="7" name="envoyer">
</div>
</form>

PHP

<?php


// Clean up the input values
foreach($_POST as $key => $value) {
if(ini_get('magic_quotes_gpc'))
$_POST[$key] = stripslashes($_POST[$key]);

$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}

// Assign the input values to variables for easy reference
$name = $_POST["name"];
$tel= $_POST["tel"];
$email = $_POST["email"];
$city= $_POST["city"];
$activity= $_POST["activity"];
$message = $_POST["message"];

// Test input values for errors
$errors = array();
if(strlen($name) < 2) {
if(!$name) {
$errors[] = "You must enter a name.";
} else {
$errors[] = "You must enter a name.";
}
}
if(strlen($tel) < 6) {
if(!$tel) {
$errors[] = "You must enter a telephone.";
} else {
$errors[] = "You must enter a telephone.";
}
}
if(!$email) {
$errors[] = "You must enter an email.";
} else if(!validEmail($email)) {
$errors[] = "You must enter an email.";
}
if(strlen($city) < 3) {
if(!$city) {
$errors[] = "You must enter a city.";
} else {
$errors[] = "You must enter a city.";
}
}
if(strlen($activity) < 3) {
if(!$activity) {
$errors[] = "You must enter an activity.";
} else {
$errors[] = "You must enter an activity.";
}
}
if(strlen($message) < 10) {
if(!$message) {
$errors[] = "Please write a valid message";
} else {
$errors[] = "Please write a valid message";
}
}

if ($errors) 
{ 
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=http://mydomain.co/index.html#quoteform">'; 
exit ("<span class='failure'>Please fill your form again, we founf the following errors<ul>". $errortext ."</ul></span>"); 
sleep(3); 
}

// Send the email
$to = "creative@mydomain.co, creative@gmail.com";
$subject = "Contact: $name";
$message = "Name: $name 

Tel: $tel

Mail: $email 

City: $city

Activity: $activity

Comment: $message ";

$headers = "From: $email";

mail($to, $subject, $message, $headers);

// Exit with a success message

echo '<meta http-equiv="refresh" content="3; url=http://mydomain.co">';
exit;("<span class='success'>Thank you... your message has been sent succesfully... Now you'll be redirected to the main page</span>" );
sleep(3);

// A function that checks to see if
// an email is valid
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
// character not valid in local part unless 
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}

?>

--

提前感谢您给予我的支持。 问候

支持Sk.:请让我检查

我:谢谢你

Support Sk.:据我所知,您在表单的“发件人”字段中使用了第 3 方电子邮件地址。我们禁用了从不在我们的托管服务器上的电子邮件地址发送邮件。我们采取了这些措施来防止通过论坛、联系表格和其他脚本发送垃圾邮件。这意味着您不能在邮件表单的 FROM 字段中使用非本地电子邮件地址。

Support Sk.:如果您仍然想在表单中使用非本地电子邮件地址,我们可以为您的帐户开放25端口。

我:是的,请,因为我真的需要它。

Support Sk.:在这种情况下,我需要先完成验证,然后才能协助您处理请求。为了验证您的托管帐户,请向我提供以下信息: 主域名:Namecheap 帐户用户名:cPanel 用户名:Namecheap 支持引脚。你可以在这里找到它:https://manage.www.namecheap.com/myaccount/modify-profile-supportsettings.aspx

我:好的,用户名:XXXXXX CPanel 用户:rdxvimy 支持密码:xxxx

Support Sk.:我们已经为您开放了 25 端口。请注意,在这种情况下,您应该在表单中指定 Gmail 服务器而不是我们的服务器

我:Gmail 服务器,那我应该写什么呢?

Support Sk.:您应该指定创建 rcreative@gmail.com 的服务器

我:不好意思,我不明白... creative@gmail.com 是访问者的邮箱,他以网站的形式写了他的电子邮件,所以我可以在之后回复他

Support Sk.:很抱歉造成混乱。您应该在表单中使用以下设置: Gmail SMTP 服务器地址:smtp.gmail.com Gmail SMTP 用户名:您的完整 Gmail 地址


到此结束...我非常感谢您提供的任何帮助。谢谢

【问题讨论】:

  • 您的支持人员基本上是在告诉您通过 SMTP 而不是通过本地邮件服务器发送邮件。我强烈推荐使用github.com/PHPMailer/PHPMailer,查看示例文件夹中的 SMTP 示例。
  • 谢谢克里斯托弗,我看看能不能成功

标签: php forms email smtp contact


【解决方案1】:

我最近遇到了这个问题。在进行了一些挖掘之后,我了解到使用 namecheap 时的来自电子邮件必须来自当前托管在 namecheap 服务器上的域。希望有一天这可以帮助其他人。

https://www.namecheap.com/support/knowledgebase/article.aspx/859/0/-from-field

【讨论】:

  • 绞尽脑汁大约 4 小时后,我偶然发现了这个解决方案,并且它奏效了。甚至 Namecheap 的支持人员也不知道。
  • 我发现如果您需要使用与可用域不匹配的“发件人”地址,最好的解决方法是将发件人设置为名称便宜的托管域,并设置回复- 到您想要的发件人地址。然后,对该电子邮件的任何回复都将被定向到正确的位置。
【解决方案2】:

您需要根据与支持代表的对话更改您的 SMTP 设置。这些是在你的 PHP.INI 中设置的

【讨论】:

  • Ty,但我没有 php.ini 并且不知道如何应用支持参考的响应。如果你能给我一个像指南这样的“傻瓜”,真的很感激
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-22
  • 1970-01-01
  • 1970-01-01
  • 2019-03-18
  • 2016-03-29
  • 2017-05-27
  • 2013-08-16
相关资源
最近更新 更多