我已经使用 Prestashop 设置了一个电子商务网站,在测试他们的联系表单时,我发现如果用户输入雅虎电子邮件地址作为发件人地址,我不会收到任何消息。但是,如果用户输入 Gmail 地址,我没有任何问题。
Prestashop 当前设置为使用 PHP Mail() 函数作为联系表单。可能是什么问题以及我可以考虑什么解决方案,因为我显然需要接收来自每个人的邮件,而不仅仅是那些具有 gmail 地址的邮件。
以下是 contact-form.php 页面中的代码:-
<?php
$useSSL = true;
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
$errors = array();
$smarty->assign('contacts', Contact::getContacts(intval($cookie->id_lang)));
if (Tools::isSubmit('submitMessage'))
{
if (!($from = Tools::getValue('from')) OR !Validate::isEmail($from))
$errors[] = Tools::displayError('invalid e-mail address');
elseif (!($message = nl2br2(Tools::getValue('message'))))
$errors[] = Tools::displayError('message cannot be blank');
elseif (!Validate::isMessage($message))
$errors[] = Tools::displayError('invalid message');
elseif (!($id_contact = intval(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact(intval($id_contact), intval($cookie->id_lang)))))
$errors[] = Tools::displayError('please select a contact in the list');
else
{
if (intval($cookie->id_customer))
$customer = new Customer(intval($cookie->id_customer));
if (Mail::Send(intval($cookie->id_lang), 'contact', 'Message from contact form', array('{email}' => $_POST['from'], '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, (intval($cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $from)))
$smarty->assign('confirmation', 1);
else
$errors[] = Tools::displayError('an error occurred while sending message');
}
}
$email = Tools::safeOutput(Tools::getValue('from', ((isset($cookie) AND isset($cookie->email) AND Validate::isEmail($cookie->email)) ? $cookie->email : '')));
$smarty->assign(array(
'errors' => $errors,
'email' => $email
));
$smarty->display(_PS_THEME_DIR_.'contact-form.tpl');
include(dirname(__FILE__).'/footer.php');
?>
更新:
我联系了我的电子邮件托管公司,他们给出了以下建议:-
您需要更改电子邮件
$from 到 any 字段中的地址
域名上的电子邮件地址
你正在合并这个
脚本。例如,如果您的域
名称是 abc.com,那么您将定义
发件人电子邮件地址为
[电子邮件受保护]。这个电子邮件地址
不需要存在于邮件中
然而,abc.com 的服务器,域
$from 字段中的名称必须是
你的。您可以使用电子邮件地址
例如[电子邮件受保护]。
$mailto 字段中的值需要
更改为电子邮件地址,
其中包含数据的电子邮件
通过表格提交需要
已交付。
那么在 Prestashop 的 contact-form.php (上面给出的代码)的上下文中,我将如何更改它?
I've setup an ecommerce site using Prestashop and when testing their contact form, I found that I was not receiving any messages if user enters Yahoo email address as the senders address. I have no problems, however, if the user enters a Gmail address.
Prestashop is set up currently to use the PHP Mail() function for the contact form. What could be the problem and what solutions could I look at as I obviously need to receive mails from everyone, not just those with gmail addresses.
The following is the code in the contact-form.php page:-
<?php
$useSSL = true;
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
$errors = array();
$smarty->assign('contacts', Contact::getContacts(intval($cookie->id_lang)));
if (Tools::isSubmit('submitMessage'))
{
if (!($from = Tools::getValue('from')) OR !Validate::isEmail($from))
$errors[] = Tools::displayError('invalid e-mail address');
elseif (!($message = nl2br2(Tools::getValue('message'))))
$errors[] = Tools::displayError('message cannot be blank');
elseif (!Validate::isMessage($message))
$errors[] = Tools::displayError('invalid message');
elseif (!($id_contact = intval(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact(intval($id_contact), intval($cookie->id_lang)))))
$errors[] = Tools::displayError('please select a contact in the list');
else
{
if (intval($cookie->id_customer))
$customer = new Customer(intval($cookie->id_customer));
if (Mail::Send(intval($cookie->id_lang), 'contact', 'Message from contact form', array('{email}' => $_POST['from'], '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, (intval($cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $from)))
$smarty->assign('confirmation', 1);
else
$errors[] = Tools::displayError('an error occurred while sending message');
}
}
$email = Tools::safeOutput(Tools::getValue('from', ((isset($cookie) AND isset($cookie->email) AND Validate::isEmail($cookie->email)) ? $cookie->email : '')));
$smarty->assign(array(
'errors' => $errors,
'email' => $email
));
$smarty->display(_PS_THEME_DIR_.'contact-form.tpl');
include(dirname(__FILE__).'/footer.php');
?>
UPDATE:
I contacted my email hosting company and they gave the following suggestion:-
You would need to change the Email
address in the field $from to any
Email address on the domain name on
which you are incorporating this
script. For example, if your Domain
Name is abc.com, then you would define
the From Email address as
[email protected]. This Email address
need not be existing on the Mail
Server of abc.com, however, the domain
name in the $from field has to be
yours. You may use an Email address
such as [email protected].
The value in the $mailto field needs
to be changed to the Email address,
where email containing the data
submitted through the form needs to be
delivered.
So in the context of Prestashop's contact-form.php (code given above), how would I go about changing it?
发布评论
评论(5)
PHP mail() 确实是一种发送电子邮件的原始方式。如果您不太了解电子邮件 RFC(标准),则很容易用 mail() 搞砸事情......
我建议您使用 PHPMailer(或类似的库)或发布您使用的实际代码。
PHP mail() is really a raw way to send emails. It's quite easy to screw up things with mail() if you don't know well the email RFCs (standards)...
I suggest you to use PHPMailer (or similar librairies) or post the actual code your using.
您不能使用未绑定到您的服务器的地址作为发件人地址。这将被每一个有自尊的垃圾邮件阻止机制所阻止。它与 GMail 地址一起使用实际上是一个奇迹。
如果您希望能够直接回复人们通过联系表单发送给您的邮件,请将以下标头添加到您的
mail()
调用的第四个参数中:但作为实际发件人地址, 总是使用
You can't use addresses that are not bound to your servers as sender addresses. This will be blocked by every self-respecting spam blocking mechanism. It's actually a miracle that it works with GMail addresses.
If you want to be able to directly reply to mails that people send to you through your contact form, add the following header to the 4th parameter to your
mail()
call:but as the physical sender address, always use
您可以向
mail()
调用提供第五个参数。这是我用来修复我的 drupal 邮件的内容(简化版):
由于 AlexV 正确地指出使用未转义的值是危险的,因此这是完整版本。请注意,它取自 drupal 源(有一个小修复)。
希望有帮助,
克里斯
There's a fifth parameter you can supply to the
mail()
call.Here is what I used to fix my drupal mail (simplified):
Since AlexV correctly remarked that using unescaped values is dangerous, this is the full version. Please note that it is taken from the drupal sources (with a small fix).
Hope that helps,
Chris
我一直在使用这个小代码在我自己的时事通讯系统中发送电子邮件。这段摘录专门处理一条消息。它基于 RFC 规范。
I've been using this small code to send e-mails in a newsletter system of my own. This excerpt handles specifically a single message. It's based on RFC specs.
我将“from”更改为
$_REQUEST['from']
。您也可以更改它$_POST['from']
。将 2 'from' 替换为此,并将$contact->email
更改为您想要发送该电子邮件的任何所需电子邮件。它对我有用。
I changed the 'from' to
$_REQUEST['from']
. You can change it$_POST['from']
as well. replace 2 'from' with this and change$contact->email
to any desired email where you want to deliver that email.it worked for me.