Opencart mail sorununa çözüm

Opencart online alışveriş sisteminiz müşterilere sipariş maillerini göndermiyor mu? İletişim Formu size gelmiyor mu?
Gelen ve giden formlarda türkçe karakterler bozuk mu çıkıyor? system/library/mail.php dosyasını aşağıdaki kodla değiştirşin:
Opencart sürüm 1.5.1.3.1 te denenmiştir.

<?php
final class Mail {
    protected $to;
    protected $from;
    protected $sender;
    protected $subject;
    protected $text;
    protected $html;
    protected $attachments = array();
    public $protocol = &#39;mail&#39;;
    public $hostname;
    public $username;
    public $password;
    public $port = 25;
    public $timeout = 5;
    public $newline = &quot;\r\n&quot;;
    public $crlf = &quot;\r\n&quot;;
    public $verp = FALSE;
    public $parameter = &#39;&#39;;

    public function setTo($to) {
        $this->to = $to;
    }

    public function setFrom($from) {
        $this->from = $from;
    }

    public function addheader($header, $value) {
        $this->headers[$header] = $value;
    }

    public function setSender($sender) {
        $this->sender = html_entity_decode($sender);
    }

 public function setSubject($subject) {
      $this->subject = &#39;=?UTF-8?B?&#39; . base64_encode($subject) . &#39;?=&#39;;
   }

    public function setText($text) {
        $this->text = $text;

    }

    public function setHtml($html) {
        $this->html = $html;
    }

    public function addAttachment($file, $filename = &#39;&#39;) {
        if (!$filename) {
            $filename = basename($file);
        }

        $this->attachments[] = array(
            &#39;filename&#39; => $filename,
            &#39;file&#39;     => $file
        );
    }

    public function send() {
        if (!$this->to) {
            exit(&#39;Error: E-Mail to required!&#39;);
        }

        if (!$this->from) {
            exit(&#39;Error: E-Mail from required!&#39;);
        }

        if (!$this->sender) {
            exit(&#39;Error: E-Mail sender required!&#39;);
        }

        if (!$this->subject) {
            exit(&#39;Error: E-Mail subject required!&#39;);
        }

        if ((!$this->text) &amp;&amp; (!$this->html)) {
            exit(&#39;Error: E-Mail message required!&#39;);
        }

        if (is_array($this->to)) {
            $to = implode(&#39;,&#39;, $this->to);
        } else {
            $to = $this->to;
        }

        $boundary = &#39;----=_NextPart_&#39; . md5(time());

        $header = &#39;&#39;;

        if ($this->protocol != &#39;mail&#39;) {
            $header .= &#39;To: &#39; . $to . $this->newline;
            $header .= &#39;Subject: &#39; . $this->subject . $this->newline;
        }

        $header .= &#39;Date: &#39; . date(&quot;D, d M Y H:i:s O&quot;) . $this->newline;
        //$header .= &#39;From: &quot;&#39; . $this->sender . &#39;&quot; <&#39; . $this->from . &#39;>&#39; . $this->newline;
        //$header .= &#39;From: &#39; . $this->sender . &#39;<&#39; . $this->from . &#39;>&#39; . $this->newline;
        $header .= &#39;From: &#39; . &#39;=?UTF-8?B?&#39;.base64_encode($this->sender).&#39;?=&#39; . &#39;<&#39; . $this->from . &#39;>&#39; . $this->newline;
        $header .= &#39;Reply-To: &#39; . $this->sender . &#39;<&#39; . $this->from . &#39;>&#39; . $this->newline;
        $header .= &#39;Return-Path: &#39; . $this->from . $this->newline;
        $header .= &#39;X-Mailer: PHP/&#39; . phpversion() . $this->newline;
        $header .= &#39;MIME-Version: 1.0&#39; . $this->newline;
        $header .= &#39;Content-Type: multipart/mixed; boundary=&quot;&#39; . $boundary . &#39;&quot;&#39; . $this->newline;
        $header .= &#39;Content-Transfer-Encoding: 8bit&#39; . $this->newline;
        $header .= $this->newline;

        if (!$this->html) {
            $message  = &#39;--&#39; . $boundary . $this->newline;
            $message .= &#39;Content-Type: text/plain; charset=&quot;utf-8&quot;&#39; . $this->newline;
            $message .= &#39;Content-Transfer-Encoding: 8bit&#39; . $this->newline . $this->newline;
            $message .= $this->text . $this->newline;
        } else {
            $message  = &#39;--&#39; . $boundary . $this->newline;
            $message .= &#39;Content-Type: multipart/alternative; boundary=&quot;&#39; . $boundary . &#39;_alt&quot;&#39; . $this->newline . $this->newline;
            $message .= &#39;--&#39; . $boundary . &#39;_alt&#39; . $this->newline;
            $message .= &#39;&#39; . $this->newline;
            $message .= &#39;&#39; . $this->newline;

            if ($this->text) {
                $message .= $this->text . $this->newline;
            } else {
                $message .= &#39;&#39; . $this->newline;
            }

            $message .= &#39;--&#39; . $boundary . &#39;_alt&#39; . $this->newline;
            $message .= &#39;Content-Type: text/html; charset=&quot;utf-8&quot;&#39; . $this->newline;
            $message .= &#39;Content-Transfer-Encoding: 8bit&#39; . $this->newline . $this->newline;
            $message .= $this->html . $this->newline;
            $message .= &#39;--&#39; . $boundary . &#39;_alt--&#39; . $this->newline;
        }

foreach ($this->attachments as $attachment) {
         if (file_exists($attachment['file'])) {
            $handle = fopen($attachment['file'], &#39;r&#39;);
            $content = fread($handle, filesize($attachment['file']));

            fclose($handle);

            $message .= &#39;--&#39; . $boundary . $this->newline;
            $message .= &#39;Content-Type: application/octetstream&#39; . $this->newline;
            $message .= &#39;Content-Transfer-Encoding: base64&#39; . $this->newline;
            $message .= &#39;Content-Disposition: attachment; filename=&quot;&#39; . basename($attachment['filename']) . &#39;&quot;&#39; . $this->newline;
            $message .= &#39;Content-ID: <&#39; . basename($attachment['filename']) . &#39;>&#39; . $this->newline . $this->newline;
            $message .= chunk_split(base64_encode($content));
         }
      }

        $message .= &#39;--&#39; . $boundary . &#39;--&#39; . $this->newline;

        if ($this->protocol == &#39;mail&#39;) {
            ini_set(&#39;sendmail_from&#39;, $this->from);

            if ($this->parameter) {
                mail($to, &#39;=?UTF-8?B?&#39;.base64_encode($this->subject).&#39;?=&#39;, $message, $header, $this->parameter);
            } else {
                mail($to, &#39;=?UTF-8?B?&#39;.base64_encode($this->subject).&#39;?=&#39;, $message, $header);
            }

        } elseif ($this->protocol == &#39;smtp&#39;) {
            $handle = fsockopen($this->hostname, $this->port, $errno, $errstr, $this->timeout);

            if (!$handle) {
                error_log(&#39;Error: &#39; . $errstr . &#39; (&#39; . $errno . &#39;)&#39;);
            } else {
                if (substr(PHP_OS, 0, 3) != &#39;WIN&#39;) {
                    socket_set_timeout($handle, $this->timeout, 0);
                }

                while ($line = fgets($handle, 515)) {
                    if (substr($line, 3, 1) == &#39; &#39;) {
                        break;
                    }
                }

                if (substr($this->hostname, 0, 3) == &#39;tls&#39;) {
                    fputs($handle, &#39;STARTTLS&#39; . $this->crlf);

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if (substr($reply, 0, 3) != 220) {
                        error_log(&#39;Error: STARTTLS not accepted from server!&#39;);
                    }
                }

                if (!empty($this->username)  &amp;&amp; !empty($this->password)) {
                    fputs($handle, &#39;EHLO &#39; . getenv(&#39;SERVER_NAME&#39;) . $this->crlf);

                    $reply = &#39;&#39;;

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if (substr($reply, 0, 3) != 250) {
                        error_log(&#39;Error: EHLO not accepted from server!&#39;);
                    }

                    fputs($handle, &#39;AUTH LOGIN&#39; . $this->crlf);

                    $reply = &#39;&#39;;

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if (substr($reply, 0, 3) != 334) {
                        error_log(&#39;Error: AUTH LOGIN not accepted from server!&#39;);
                    }

                    fputs($handle, base64_encode($this->username) . $this->crlf);

                    $reply = &#39;&#39;;

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if (substr($reply, 0, 3) != 334) {
                        error_log(&#39;Error: Username not accepted from server!&#39;);
                    }

                    fputs($handle, base64_encode($this->password) . $this->crlf);

                    $reply = &#39;&#39;;

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if (substr($reply, 0, 3) != 235) {
                        error_log(&#39;Error: Password not accepted from server!&#39;);
                    }
                } else {
                    fputs($handle, &#39;HELO &#39; . getenv(&#39;SERVER_NAME&#39;) . $this->crlf);

                    $reply = &#39;&#39;;

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if (substr($reply, 0, 3) != 250) {
                        error_log(&#39;Error: HELO not accepted from server!&#39;);
                    }
                }

                if ($this->verp) {
                    fputs($handle, &#39;MAIL FROM: <&#39; . $this->username . &#39;>XVERP&#39; . $this->crlf);
                } else {
                    fputs($handle, &#39;MAIL FROM: <&#39; . $this->username . &#39;>&#39; . $this->crlf);
                }

                $reply = &#39;&#39;;

                while ($line = fgets($handle, 515)) {
                    $reply .= $line;

                    if (substr($line, 3, 1) == &#39; &#39;) {
                        break;
                    }
                }

                if (substr($reply, 0, 3) != 250) {
                    error_log(&#39;Error: MAIL FROM not accepted from server!&#39;);
                }

                if (!is_array($this->to)) {
                    fputs($handle, &#39;RCPT TO: <&#39; . $this->to . &#39;>&#39; . $this->crlf);

                    $reply = &#39;&#39;;

                    while ($line = fgets($handle, 515)) {
                        $reply .= $line;

                        if (substr($line, 3, 1) == &#39; &#39;) {
                            break;
                        }
                    }

                    if ((substr($reply, 0, 3) != 250) &amp;&amp; (substr($reply, 0, 3) != 251)) {
                        error_log(&#39;Error: RCPT TO not accepted from server!&#39;);
                    }
                } else {
                    foreach ($this->to as $recipient) {
                        fputs($handle, &#39;RCPT TO: <&#39; . $recipient . &#39;>&#39; . $this->crlf);

                        $reply = &#39;&#39;;

                        while ($line = fgets($handle, 515)) {
                            $reply .= $line;

                            if (substr($line, 3, 1) == &#39; &#39;) {
                                break;
                            }
                        }

                        if ((substr($reply, 0, 3) != 250) &amp;&amp; (substr($reply, 0, 3) != 251)) {
                            error_log(&#39;Error: RCPT TO not accepted from server!&#39;);
                        }
                    }
                }

                fputs($handle, &#39;DATA&#39; . $this->crlf);

                $reply = &#39;&#39;;

                while ($line = fgets($handle, 515)) {
                    $reply .= $line;

                    if (substr($line, 3, 1) == &#39; &#39;) {
                        break;
                    }
                }

                if (substr($reply, 0, 3) != 354) {
                    error_log(&#39;Error: DATA not accepted from server!&#39;);
                }

                fputs($handle, $header . $message . $this->crlf);
                fputs($handle, &#39;.&#39; . $this->crlf);

                $reply = &#39;&#39;;

                while ($line = fgets($handle, 515)) {
                    $reply .= $line;

                    if (substr($line, 3, 1) == &#39; &#39;) {
                        break;
                    }
                }

                if (substr($reply, 0, 3) != 250) {
                    error_log(&#39;Error: DATA not accepted from server!&#39;);
                }

                fputs($handle, &#39;QUIT&#39; . $this->crlf);

                $reply = &#39;&#39;;

                while ($line = fgets($handle, 515)) {
                    $reply .= $line;

                    if (substr($line, 3, 1) == &#39; &#39;) {
                        break;
                    }
                }

                if (substr($reply, 0, 3) != 221) {
                    error_log(&#39;Error: QUIT not accepted from server!&#39;);
                }

                fclose($handle);
            }
        }
    }
}
?>

1 yorum

Yorum Gönderin

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir