-1

Prestashop を使用して e コマース サイトをセットアップしましたが、コンタクト フォームをテストしたところ、ユーザーが送信者アドレスとして 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 の場合、From Email アドレスを 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

「から」を に変更しました$_REQUEST['from']。変更することもでき$_POST['from']ます。2 'from' をこれに置き換え$contact->email、そのメールを配信したい任意のメールに変更します。

それは私のために働いた。

于 2011-09-16T14:13:01.970 に答える
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

呼び出しに指定できる 5 番目のパラメーターがあり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 に答える