-1

我使用 Prestashop 建立了一个电子商务网站,在测试他们的联系表时,我发现如果用户输入 Yahoo 电子邮件地址作为发件人地址,我没有收到任何消息。但是,如果用户输入 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 中的电子邮件地址更改为要合并此脚本的域名上的任何电子邮件地址。例如,如果您的域名是 abc.com,那么您可以将发件人电子邮件地址定义为 some-name@abc.com。此电子邮件地址不必存在于 abc.com 的邮件服务器上,但是,$from 字段中的域名必须是您的。您可以使用电子邮件地址,例如 Do_Not_reply@abc.com。

$mailto 字段中的值需要更改为电子邮件地址,其中包含通过表单提交的数据的电子邮件需要发送。

因此,在 Prestashop 的contact-form.php(上面给出的代码)的上下文中,我将如何更改它?

4

5 回答 5

1

PHP mail() 确实是一种发送电子邮件的原始方式。如果您不太了解电子邮件 RFC(标准),那么使用 mail() 很容易搞砸事情......

我建议您使用PHPMailer(或类似的库)或发布您使用的实际代码。

于 2010-01-25T15:51:11.077 回答
1

您不能将未绑定到服务器的地址用作发件人地址。这将被每个自尊的垃圾邮件阻止机制阻止。它与 GMail 地址一起工作实际上是一个奇迹。

如果您希望能够直接回复人们通过您的联系表发送给您的邮件,请将以下标题添加到您的mail()呼叫的第 4 个参数:

reply-to: customers_email_address

但作为物理发件人地址,请始终使用

from: something@yourserver.com
于 2010-01-25T15:52:01.030 回答
0

您可以为mail()调用提供第五个参数。

这是我用来修复我的 drupal 邮件的内容(简化版):

return @mail($message['to'],
             $message['subject'],
             $message['body'],
             join("\n", $mimeheaders),
             '-f' . $message['from'] );

由于 AlexV 正确地指出使用未转义的值是危险的,因此这是完整版本。请注意,它取自 drupal 资源(有一个小修复)。

    function drupal_mail_wrapper($message)
    {
        $mimeheaders = array();

        foreach ($message['headers'] as $name => $value) 
        {
            $mimeheaders[] = $name .': '. mime_header_encode($value);
        }

        return @mail(
            $message['to'],
            mime_header_encode($message['subject']),
            // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
            // They will appear correctly in the actual e-mail that is sent.
            str_replace("\r", '', $message['body']),
            // For headers, PHP's API suggests that we use CRLF normally,
            // but some MTAs incorrecly replace LF with CRLF. See #234403.
            join("\n", $mimeheaders),
            ($message['from'] ? '-f' . $message['from'] : '') );
    }

希望有帮助,克里斯

于 2010-01-25T16:19:06.567 回答
0

我一直在使用这个小代码在我自己的通讯系统中发送电子邮件。此摘录专门处理单个消息。它基于 RFC 规范。


    /**
     * @package  jaMailBroadcast
     * @author   Joel A. Villarreal Bertoldi (design at joelalejandro.com)
     *
     * @usage    
     *
     *     $msg = new jaMailBroadcast_Message("My Website", "my@website.com");
     *     $msg->to = new jaMailBroadcast_Contact("John Doe", "john@doe.com");
     *     $msg->subject = "Something";
     *     $msg->body = "Your message here. You <b>can use</b> HTML.";
     *     $msg->send();
     **/

    class jaMailBroadcast_Contact
    {
        public $id;
        public $name;
        public $email;

        function __construct($contactName, $contactEmail, $contactId = "")
        {
            $this->name = $contactName;
            $this->email = $contactEmail;
            if (!$contactId)
                $this->id = uniqid("contact_");
            else
                $this->id = $contactId;
        }

        function __toString()
        {
            return json_encode
            (
                array
                (
                  "id" => $this->id,
                  "name" => $this->name,
                  "email" => $this->email
                )
            );
        }

        function rfc882_header()
        {
            return sprintf('"%s" ', $this->name, $this->email);
        }
    }

    class jaMailBroadcast_Message
    {
        public $from;
        public $to;
        public $subject;
        public $body;
        public $mime_boundary;
        public $headerTemplate;
        public $footerTemplate;

        function __construct($fromName, $fromEmail)
        {
            $this->from = new jaMailBroadcast_Contact($fromName, $fromEmail);
            $this->mime_boundary = "==" . md5(time());
        }

        private function mail_headers($EOL = "\n")
        {
            $headers
              = "From: " . $this->from->rfc882_header() . $EOL
              . "Reply-To: from->email . ">" . $EOL
              . "Return-Path: from->email . ">" . $EOL
              . "MIME-Version: 1.0" . $EOL
              . "Content-Type: multipart/alternative; boundary=\"{$this->mime_boundary}\"" . $EOL
              . "User-Agent: jaMailBroadcast/1.0" . $EOL
              . "X-Priority: 3 (Normal)" . $EOL
              . "Importance: Normal" . $EOL
              . "X-Mailer: jaMailBroadcast";

            return $headers;
        }

        private function rfc882_body_format($EOL = "\r\n")
        {
          return wordwrap($this->body, 70, $EOL);
        }

        function send()
        {
            $EOL =
                 (
                    stripos($this->to->email, "hotmail") !== false
                  ||
                    stripos($this->to->email, "live") !== false
                 )
                  ? "\n"
                  : "\n";

            return mail
            (
                $this->to->rfc882_header(),
                $this->subject,
                $this->multipart_alternative_body($EOL),
                $this->mail_headers($EOL),
                "-f" . $this->from->email
            );
        }

        private function multipart_alternative_body($EOL = "\r\n")
        {
            $multipart
                    = "Content-Transfer-Encoding: 7bit" . $EOL
                    . "This is a multi-part message in MIME format. This part of the E-mail should never be seen. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client." . $EOL . $EOL
                    = "--{$this->mime_boundary}" . $EOL
                    . "Content-Type: text/plain; charset=iso-8859-1" . $EOL
                    . "Content-Transfer-Encoding: 7bit" . $EOL . $EOL
                    . strip_tags($this->br2nl($this->headerTemplate)) . $EOL . $EOL
                    . strip_tags($this->br2nl($this->body)) . $EOL . $EOL
                    . strip_tags($this->br2nl($this->footerTemplate)) . $EOL . $EOL
                    . "--{$this->mime_boundary}" . $EOL
                    . "Content-Type: text/html; charset=iso-8859-1" . $EOL
                    . "Content-Transfer-Encoding: 7bit" . $EOL . $EOL
                    . $this->headerTemplate . $EOL
                    . $this->body . $EOL
                    . $this->footerTemplate . $EOL
                    . "--{$this->mime_boundary}--" . $EOL;

            return $multipart;
        }

        private function br2nl($text, $EOL = "\n")
        {
            $text = str_ireplace("<br>", $EOL, $text);
            $text = str_ireplace("<br />", $EOL, $text);
            return $text;
        }
    }

于 2010-01-25T16:20:11.197 回答
0

我将“从”更改为$_REQUEST['from']. 你也可以改变它$_POST['from']。用此替换 2 'from' 并更改$contact->email为您要发送该电子邮件的任何所需电子邮件。

它对我有用。

于 2011-09-16T14:13:01.970 回答