PHP Mail () Contattateci modulo funziona bene se entrare in un Gmail invio di indirizzo, ma non con Yahoo [duplicato]

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

Domanda

    

Questa domanda è un esatto duplicato di:

         

Ho installato un sito di e-commerce con PrestaShop e quando prova la loro modulo di contatto, ho scoperto che non riceveva alcun messaggio se l'utente inserisce Yahoo indirizzo email come mittenti indirizzi. Non ho problemi, tuttavia, se l'utente inserisce un indirizzo Gmail.

Prestashop è configurato attualmente per utilizzare la funzione PHP Mail () per il modulo di contatto. Quale potrebbe essere il problema e quali soluzioni ho potuto osservare come ho ovviamente bisogno di ricevere mail da parte di tutti, non solo quelli con indirizzi Gmail.

Quello che segue è il codice nella pagina di contatto-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');

?> 

UPDATE:
Ho contattato la mia e-mail società di hosting e hanno dato la seguente proposta: -

  

Si avrebbe bisogno di cambiare l'e-mail   affrontare nel campo $ da qualsiasi   Indirizzo e-mail sul nome di dominio su   che si sta incorporando questo   script. Ad esempio, se il dominio   Nome è abc.com, allora si definirebbe   Da indirizzo e-mail come   some-name@abc.com. Questo indirizzo e-mail   non deve essere esistente sulla posta   Server di abc.com, tuttavia, il dominio   nome nel $ da campo deve essere   il tuo. Si può utilizzare un indirizzo e-mail   come ad esempio Do_Not_reply@abc.com.

     

Il valore in $ mailto esigenze di campo   di essere cambiato all'indirizzo e-mail,   dove e-mail contenente i dati   inviate tramite il modulo deve essere   consegnato.

Quindi, nel contesto di contatto form.php di Prestashop (codice di cui sopra), come potrei fare per cambiarlo?

È stato utile?

Soluzione 5

La soluzione per questo è stata trovata come questa domanda è quasi identica a: - Riconfigurazione PHP mail () Smarty Modulo di contatto .

Altri suggerimenti

PHP mail () è davvero un modo grezzo per inviare messaggi di posta elettronica. E 'abbastanza facile da rovinare le cose con la posta () se non si conoscono bene le RFC e-mail (standard) ...

Vi suggerisco di utilizzare PHPMailer (o Librairies simili) oppure inviare il codice vero e vostro usando.

Non è possibile usare gli indirizzi che non sono legati ai server come indirizzi dei mittenti. Questo sarà bloccato da ogni meccanismo il blocco dello spam che si rispetti. In realtà è un miracolo che funziona con gli indirizzi Gmail.

Se si vuole essere in grado di rispondere direttamente alle mail che le persone inviano a voi attraverso il vostro modulo di contatto, aggiungere la seguente intestazione al 4 ° parametro alla chiamata mail():

reply-to: customers_email_address

ma come indirizzo del mittente fisico, sempre usare

from: something@yourserver.com

C'è un quinto parametro è possibile fornire alla chiamata mail().

Ecco quello che ho usato per fissare la mia posta Drupal (semplificato):

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

Da AlexV correttamente osservato che utilizzando valori escape è pericolosa, questa è la versione completa. Si prega di notare che è preso dalle fonti Drupal (con una piccola correzione).

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

Speranza che aiuta, Chris

Ho usato questo piccolo codice per inviare messaggi di posta elettronica in un sistema di newsletter del mio. Questo estratto gestisce specificamente un singolo messaggio. Si basa su specifiche 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;
        }
    }

Ho cambiato il 'da' a $_REQUEST['from']. Si può cambiare $_POST['from'] pure. sostituire 2 'da' con questo e cambiare $contact->email a qualsiasi e-mail dove si desidera consegnare che la posta elettronica.

ha funzionato per me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top