يعمل نموذج PHP Mail () Contact-US بشكل جيد إذا دخل عنوان إرسال Gmail ، ولكن ليس مع Yahoo [مكرر

StackOverflow https://stackoverflow.com/questions/2133442

سؤال

هذا السؤال هو مكرر دقيق ل:

لقد قمت بإعداد موقع للتجارة الإلكترونية باستخدام Prestashop وعند اختبار نموذج الاتصال الخاص بهم ، وجدت أنني لا أتلقى أي رسائل إذا قام المستخدم بإدخال عنوان البريد الإلكتروني Yahoo كعنوان المرسلين. ليس لدي أي مشاكل ، ومع ذلك ، إذا دخل المستخدم عنوان Gmail.

تم إعداد Prestashop حاليًا لاستخدام وظيفة PHP Mail () لنموذج الاتصال. ما الذي يمكن أن يكون المشكلة وما هي الحلول التي يمكن أن أنظر إليها حيث من الواضح أنني بحاجة إلى تلقي رسائل من الجميع ، وليس فقط تلك التي لديها عناوين Gmail.

ما يلي هو الرمز في صفحة الاتصال 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');

?> 

تحديث:
اتصلت بشركة استضافة البريد الإلكتروني الخاصة بي وأقدموا الاقتراح التالي:-

ستحتاج إلى تغيير عنوان البريد الإلكتروني في الحقل $ من أي عنوان بريد إلكتروني على اسم المجال الذي تقوم بدمجه هذا البرنامج النصي. على سبيل المثال ، إذا كان اسم المجال الخاص بك هو ABC.com ، فستقوم بتحديد عنوان البريد الإلكتروني من some-name@abc.com. لا يجب أن يكون عنوان البريد الإلكتروني هذا موجودًا على خادم البريد في ABC.com ، ومع ذلك ، يجب أن يكون اسم المجال في الحقل $ من الحقل. يمكنك استخدام عنوان بريد إلكتروني مثل do_not_reply@abc.com.

يجب تغيير القيمة في حقل Mailto $ إلى عنوان البريد الإلكتروني ، حيث يجب تسليم البريد الإلكتروني الذي يحتوي على البيانات المقدمة من خلال النموذج.

لذلك في سياق Contact-form.php الخاص بـ Prestashop (الرمز أعلاه) ، كيف يمكنني تغييره؟

هل كانت مفيدة؟

المحلول 5

تم العثور على حل هذا لأن هذه الأسئلة متطابقة تقريبًا مع:- إعادة تكوين نموذج الاتصال الذكي PHP ().

نصائح أخرى

PHP Mail () هي في الحقيقة طريقة خام لإرسال رسائل البريد الإلكتروني. من السهل جدًا تثبيت الأشياء باستخدام Mail () إذا كنت لا تعرف جيدًا RFCs البريد الإلكتروني (المعايير) ...

أقترح عليك استخدام phpmailer (أو مكتبة مماثلة) أو نشر الكود الفعلي الذي تستخدمه.

لا يمكنك استخدام العناوين غير المرتبطة بخوادمك كعناوين المرسل. سيتم حظر هذا من خلال كل آلية منع البريد العشوائي. إنها في الواقع معجزة تعمل مع عناوين Gmail.

إذا كنت تريد أن تكون قادرًا على الرد مباشرة على رسائل البريد التي يرسلها الأشخاص إليك من خلال نموذج الاتصال الخاص بك ، فأضف الرأس التالي إلى المعلمة الرابعة لك mail() يتصل:

reply-to: customers_email_address

ولكن كعنوان المرسل المادي ، دائماً استعمال

from: something@yourserver.com

هناك معلمة خامسة يمكنك توفيرها إلى mail() يتصل.

إليكم ما اعتدت إصلاحه على بريد دروبال (مبسط):

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

نظرًا لأن AlexV لاحظ بشكل صحيح أن استخدام القيم غير المقيدة أمر خطير ، فهذه هي النسخة الكاملة. يرجى ملاحظة أنه مأخوذ من مصادر دروبال (مع إصلاح صغير).

    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'] : '') );
    }

أتمنى أن يساعد ذلك ، كريس

لقد كنت أستخدم هذا الرمز الصغير لإرسال رسائل البريد الإلكتروني في نظام إخباري خاص بي. يعالج هذا المقتطف رسالة واحدة على وجه التحديد. يعتمد على مواصفات 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;
        }
    }

لقد غيرت "من" إلى $_REQUEST['from']. يمكنك تغييره $_POST['from'] أيضًا. استبدل 2 "من" بهذا وتغيير $contact->email إلى أي بريد إلكتروني مرغوب فيه حيث تريد تسليم هذا البريد الإلكتروني.

عملت معي.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top