Jump to content

Отправка писем через SMTP


Recommended Posts

Слышали, да вот не все клиенты и участники форума про него слышали...

 

Завтра слегка переделаю инструкцию.

Ничего страшного, пусть учатся новому, а то как Корс застынут в каменном веке :)
Link to post
Share on other sites
  • 5 months later...
  • 1 month later...

Насколько я понял, папку PHPMailer надо положить в корень, а не в папку api, как написано в инструкции.

Почитайте внимательно инструкцию на github.

 

"Находим папку src, копируем из неё все файлы к себе в проект, в папку /api/PHPmailer/ (папку PHPmailer надо создать)"

Link to post
Share on other sites

Почитайте внимательно инструкцию на github.

 

"Находим папку src, копируем из неё все файлы к себе в проект, в папку /api/PHPmailer/ (папку PHPmailer надо создать)"

 

Ну так я же и говорю, что так неверно. Надо не в /api/PHPmailer/, а в /PHPmailer/ копировать файлы.

Link to post
Share on other sites
В 12.05.2019 в 09:24, bananovsv сказал:

Ну так я же и говорю, что так неверно. Надо не в /api/PHPmailer/, а в /PHPmailer/ копировать файлы.

в папке /api/PHPmailer/

должны быть файлы https://github.com/kvalood/SimplaCMS-smtp/tree/master/api/PHPMailer

 

Что конкретно не верно? 

Что не работает?

Link to post
Share on other sites
В 12.05.2019 в 09:35, ABSORBER сказал:

в папке /api/PHPmailer/

должны быть файлы https://github.com/kvalood/SimplaCMS-smtp/tree/master/api/PHPMailer

 

Что конкретно не верно? 

Что не работает?

 

Так пишет ошибку, что файлы не найдены. Если положить PHPmailer в корень, то всё работает.

Link to post
Share on other sites

Так пишет ошибку, что файлы не найдены. Если положить PHPmailer в корень, то всё работает.

в notify.php

подключение такое?

 

require 'PHPMailer/Exception.php';

require 'PHPMailer/PHPMailer.php';

require 'PHPMailer/SMTP.php';

Link to post
Share on other sites

в notify.php

подключение такое?

 

require 'PHPMailer/Exception.php';

require 'PHPMailer/PHPMailer.php';

require 'PHPMailer/SMTP.php';

 

Может быть это только у меня, я не настаиваю.

 

Но если папку положить в api, то будет так:

PHP Warning:  require(PHPMailer/Exception.php): failed to open stream: No such file or directory in /…/public_html/api/Notify.php on line 15
Edited by bananovsv
Link to post
Share on other sites

всё равно не пашет! 
сделал всё по инструкции! 
отчёт файла _test_mail.php

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /cut/public_html/api/Database.php on line 47
2019-05-10 08:12:30 Connection: opening to veles.shop:587, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => true, 'verify_peer_name' => true, 'allow_self_signed' => true, ),)
2019-05-10 08:13:10 Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known [/cut/public_html/api/PHPMailer/SMTP.php line 327]
2019-05-10 08:13:10 Connection failed. Error #2: stream_socket_client(): unable to connect to veles.shop:587 (php_network_getaddresses: getaddrinfo failed: Name or service not known) [/cut/public_html/api/PHPMailer/SMTP.php line 327]
2019-05-10 08:13:10 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

я так подозреваю, проблема в использовании TLS

Link to post
Share on other sites

всё равно не пашет! 

сделал всё по инструкции! 

отчёт файла _test_mail.php

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /cut/public_html/api/Database.php on line 47
2019-05-10 08:12:30 Connection: opening to veles.shop:587, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => true, 'verify_peer_name' => true, 'allow_self_signed' => true, ),)
2019-05-10 08:13:10 Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known [/cut/public_html/api/PHPMailer/SMTP.php line 327]
2019-05-10 08:13:10 Connection failed. Error #2: stream_socket_client(): unable to connect to veles.shop:587 (php_network_getaddresses: getaddrinfo failed: Name or service not known) [/cut/public_html/api/PHPMailer/SMTP.php line 327]
2019-05-10 08:13:10 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

я так подозреваю, проблема в использовании TLS

Напишите мне в ЛС. Контакты ниже или в профиле.

Link to post
Share on other sites
  • 5 months later...

Подскажите где ошибся в api/Notify.php не могу понять что не так . 

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
class Notify extends Simpla
{
    public $SMTPDebug = 0;
    function php_email($to, $subject, $message, $from = '', $reply_to = '')
    {
        $headers = "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/html; charset=utf-8; \r\n";
        $headers .= "From: " . $this->settings->company_name . "<$from> \r\n";
        if (!empty($reply_to))
            $headers .= "reply-to: $reply_to\r\n";
        $subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
        @mail($to, $subject, $message, $headers);
    }
    function email($to, $subject, $message, $from = '', $reply_to = '')
    {
        if (!$this->config->phpmailer_enable) {
            $this->php_mail($to, $subject, $message, $from, $reply_to);
        } else {
            $mailer = new Phpmailer();
            $mailer->IsHTML(true);
            $mailer->CharSet = "utf-8";
            $mailer->IsSMTP();
            $mailer->Host = $this->config->phpmailer_host;
            $mailer->Port = $this->config->phpmailer_port;
            if ($this->config->phpmailer_ssl == true) {
                $mailer->SMTPSecure = "ssl";
                $mailer->SMTPAutoTLS = "false";
                // Отключить проверку сертификата - https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#updating-ca-certificates
                if ($this->config->phpmailer_ssl_verify != true) {
                    $mailer->SMTPOptions = [
                        'ssl' => [
                            'verify_peer' => false,
                            'verify_peer_name' => false,
                            'allow_self_signed' => true
                        ]
                    ];
                }
            }
            $mailer->SMTPAuth = true;
            $mailer->Username = $this->config->phpmailer_user;
            $mailer->Password = $this->config->phpmailer_password;
            foreach(preg_split('/[\s,;]+/', $to) as $e) {
                $mailer->AddAddress($e);
            }
            
            $mailer->From = $mailer->Username; // $from
            $mailer->FromName = $this->settings->company_name;
            $mailer->Sender = $mailer->Username;
            $mailer->Subject = $subject;
            $mailer->Body = $message;
            $mailer->SMTPDebug = $this->SMTPDebug; // 3
            if (!$mailer->Send()) {
                if ($this->SMTPDebug) {
                    echo 'Message could not be sent.';
                    echo 'Mailer Error: ' . $mailer->ErrorInfo;
                }
                $this->php_email($to, $subject, $message, $mailer->From);
            }
        }
    }


	public function email_order_user($order_id)
	{
			if(!($order = $this->orders->get_order(intval($order_id))) || empty($order->email))
				return false;
			
			$purchases = $this->orders->get_purchases(array('order_id'=>$order->id));
			$this->design->assign('purchases', $purchases);			

			$products_ids = array();
			$variants_ids = array();
			foreach($purchases as $purchase)
			{
				$products_ids[] = $purchase->product_id;
				$variants_ids[] = $purchase->variant_id;
			}
			
			$products = array();
			foreach($this->products->get_products(array('id'=>$products_ids)) as $p)
				$products[$p->id] = $p;
				
			$images = $this->products->get_images(array('product_id'=>$products_ids));
			foreach($images as $image)
				$products[$image->product_id]->images[] = $image;
			
			$variants = array();
			foreach($this->variants->get_variants(array('id'=>$variants_ids)) as $v)
			{
				$variants[$v->id] = $v;
				$products[$v->product_id]->variants[] = $v;
			}
				
			foreach($purchases as &$purchase)
			{
				if(!empty($products[$purchase->product_id]))
					$purchase->product = $products[$purchase->product_id];
				if(!empty($variants[$purchase->variant_id]))
					$purchase->variant = $variants[$purchase->variant_id];
			}
			
			// Способ доставки
			$delivery = $this->delivery->get_delivery($order->delivery_id);
			$this->design->assign('delivery', $delivery);

			$this->design->assign('order', $order);
			$this->design->assign('purchases', $purchases);

			// Отправляем письмо
			// Если в шаблон не передавалась валюта, передадим
			if ($this->design->smarty->getTemplateVars('currency') === null) 
			{
				$this->design->assign('currency', current($this->money->get_currencies(array('enabled'=>1))));
			}
			$email_template = $this->design->fetch($this->config->root_dir.'design/'.$this->settings->theme.'/html/email_order.tpl');
			$subject = $this->design->get_var('subject');
			$this->email($order->email, $subject, $email_template, $this->settings->notify_from_email);
	
	}


	public function email_order_admin($order_id)
	{
			if(!($order = $this->orders->get_order(intval($order_id))))
				return false;
			
			$purchases = $this->orders->get_purchases(array('order_id'=>$order->id));
			$this->design->assign('purchases', $purchases);			

			$products_ids = array();
			$variants_ids = array();
			foreach($purchases as $purchase)
			{
				$products_ids[] = $purchase->product_id;
				$variants_ids[] = $purchase->variant_id;
			}

			$products = array();
			foreach($this->products->get_products(array('id'=>$products_ids)) as $p)
				$products[$p->id] = $p;

			$images = $this->products->get_images(array('product_id'=>$products_ids));
			foreach($images as $image)
				$products[$image->product_id]->images[] = $image;
			
			$variants = array();
			foreach($this->variants->get_variants(array('id'=>$variants_ids)) as $v)
			{
				$variants[$v->id] = $v;
				$products[$v->product_id]->variants[] = $v;
			}
	
			foreach($purchases as &$purchase)
			{
				if(!empty($products[$purchase->product_id]))
					$purchase->product = $products[$purchase->product_id];
				if(!empty($variants[$purchase->variant_id]))
					$purchase->variant = $variants[$purchase->variant_id];
			}
			
			// Способ доставки
			$delivery = $this->delivery->get_delivery($order->delivery_id);
			$this->design->assign('delivery', $delivery);

			// Пользователь
			$user = $this->users->get_user(intval($order->user_id));
			$this->design->assign('user', $user);

			$this->design->assign('order', $order);
			$this->design->assign('purchases', $purchases);

			// В основной валюте
			$this->design->assign('main_currency', $this->money->get_currency());

			// Отправляем письмо
			$email_template = $this->design->fetch($this->config->root_dir.'simpla/design/html/email_order_admin.tpl');
			$subject = $this->design->get_var('subject');
			$this->email($this->settings->order_email, $subject, $email_template, $this->settings->notify_from_email);
	
	}

	

	public function email_comment_admin($comment_id)
	{ 
			if(!($comment = $this->comments->get_comment(intval($comment_id))))
				return false;
			
			if($comment->type == 'product')
				$comment->product = $this->products->get_product(intval($comment->object_id));
			if($comment->type == 'blog')
				$comment->post = $this->blog->get_post(intval($comment->object_id));

			$this->design->assign('comment', $comment);

			// Отправляем письмо
			$email_template = $this->design->fetch($this->config->root_dir.'simpla/design/html/email_comment_admin.tpl');
			$subject = $this->design->get_var('subject');
			$this->email($this->settings->comment_email, $subject, $email_template, $this->settings->notify_from_email);
	}

	public function email_password_remind($user_id, $code)
	{
			if(!($user = $this->users->get_user(intval($user_id))))
				return false;
			
			$this->design->assign('user', $user);
			$this->design->assign('code', $code);

			// Отправляем письмо
			$email_template = $this->design->fetch($this->config->root_dir.'design/'.$this->settings->theme.'/html/email_password_remind.tpl');
			$subject = $this->design->get_var('subject');
			$this->email($user->email, $subject, $email_template, $this->settings->notify_from_email);
			
			$this->design->smarty->clearAssign('user');
			$this->design->smarty->clearAssign('code');
	}

	public function email_feedback_admin($feedback_id)
	{ 
			if(!($feedback = $this->feedbacks->get_feedback(intval($feedback_id))))
				return false;

			$this->design->assign('feedback', $feedback);

			// Отправляем письмо
			$email_template = $this->design->fetch($this->config->root_dir.'simpla/design/html/email_feedback_admin.tpl');
			$subject = $this->design->get_var('subject');
			$this->email($this->settings->comment_email, $subject, $email_template, "$feedback->name <$feedback->email>", "$feedback->name <$feedback->email>");
	}


}
Link to post
Share on other sites
    function email($to, $subject, $message, $from = '', $reply_to = '')
    {
        if (!$this->config->phpmailer_enable) {
            $this->php_mail($to, $subject, $message, $from, $reply_to);
        } else {
            $mailer = new Phpmailer();
            $mailer->IsHTML(true);
            $mailer->CharSet = "utf-8";
            $mailer->IsSMTP();
            $mailer->Host = $this->config->phpmailer_host;
            $mailer->Port = $this->config->phpmailer_port;
            if ($this->config->phpmailer_ssl == true) {
                $mailer->SMTPSecure = "ssl";
                $mailer->SMTPAutoTLS = "false";
                // Отключить проверку сертификата - https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#updating-ca-certificates
                if ($this->config->phpmailer_ssl_verify != true) {
                    $mailer->SMTPOptions = [
                        'ssl' => [
                            'verify_peer' => false,
                            'verify_peer_name' => false,
                            'allow_self_signed' => true
                        ]
                    ];
                }
            }
            $mailer->SMTPAuth = true;
            $mailer->Username = $this->config->phpmailer_user;
            $mailer->Password = $this->config->phpmailer_password;
            foreach(preg_split('/[\s,;]+/', $to) as $e) {
                $mailer->AddAddress($e);
            }
            
            $mailer->From = $mailer->Username; // $from
            $mailer->FromName = $this->settings->company_name;
            $mailer->Sender = $mailer->Username;
            $mailer->Subject = $subject;
            $mailer->Body = $message;
            $mailer->SMTPDebug = $this->SMTPDebug; // 3
            if (!$mailer->Send()) {
                if ($this->SMTPDebug) {
                    echo 'Message could not be sent.';
                    echo 'Mailer Error: ' . $mailer->ErrorInfo;
                }
                $this->php_email($to, $subject, $message, $mailer->From);
            }
        }
    }

    function php_email($to, $subject, $message, $from = '', $reply_to = '')
    {
        $headers = "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/html; charset=utf-8; \r\n";
        $headers .= "From: " . $this->settings->company_name . "<$from> \r\n";
        if (!empty($reply_to))
            $headers .= "reply-to: $reply_to\r\n";
        $subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
        @mail($to, $subject, $message, $headers);
    }

Поменяйте местами 

Link to post
Share on other sites
  • 2 months later...
  • 2 months later...

Не работает. 


Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /home/bahiloff/public_html/api/Database.php on line 46

Warning: Could not connect to the database: Access denied for user 'root'@'localhost' (using password: NO) in /home/bahiloff/public_html/api/Database.php on line 51

Warning: mysqli::query(): Couldn't fetch mysqli in /home/bahiloff/public_html/api/Database.php on line 90

Warning: Database::results(): Couldn't fetch mysqli in /home/bahiloff/public_html/api/Database.php on line 136

Warning: in /home/bahiloff/public_html/api/Database.php on line 136

Warning: Invalid argument supplied for foreach() in /home/bahiloff/public_html/api/Settings.php on line 28

Link to post
Share on other sites

Не работает. 

 

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /home/bahiloff/public_html/api/Database.php on line 46

 

Warning: Could not connect to the database: Access denied for user 'root'@'localhost' (using password: NO) in /home/bahiloff/public_html/api/Database.php on line 51

 

Warning: mysqli::query(): Couldn't fetch mysqli in /home/bahiloff/public_html/api/Database.php on line 90

 

Warning: Database::results(): Couldn't fetch mysqli in /home/bahiloff/public_html/api/Database.php on line 136

 

Warning: in /home/bahiloff/public_html/api/Database.php on line 136

 

Warning: Invalid argument supplied for foreach() in /home/bahiloff/public_html/api/Settings.php on line 28

 

 

у вас какие то проблемы с базой данных нет подключение. модуль тут вообще не причем.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...