没有从php联系表单接收邮件 - Namecheap答案

时间:2014-01-27 20:58:40

标签: php forms email smtp contact

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

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

-

我正在使用namecheap域和主机构建网站并创建了一封电子邮件:creative@mydomain.co

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

问题是我没有收到网站发来的表格,也没有收到我的名单邮箱和gmail帐户。

我在另一个主机域中使用了相同的表单并且工作正常,但它不适用于namecheap。我想知道我该怎么做才能使它有效,因为每当有人填写表格并提交时,我会收到以下电子邮件作为spam@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:请让我检查

我:谢谢

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

支持Sk。:如果您仍想在表单中使用非本地电子邮件地址,我们可以为您开设25个端口。

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

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

我:好的,USERNAME:XXXXXX CPanel用户:rdxvimy支持Pin:xxxx

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

我:Gmail服务器,那我该怎么写?

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

我:打扰一下,但我不明白... creative@gmail.com是以网站形式撰写电子邮件的访问者的电子邮件,所以我可以在

之后回复他。

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


所以这里结束了...我非常感谢你能给我提供的任何帮助。谢谢

2 个答案:

答案 0 :(得分:3)

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

https://example.com

答案 1 :(得分:0)

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