Author Topic: [MOD] Simple smtp sending over ssl  (Read 6361 times)

0 Members and 2 Guests are viewing this topic.

Offline Aleksey

  • Newbie
  • *
  • Posts: 37
    • View Profile
[MOD] Simple smtp sending over ssl
« on: May 16, 2020, 10:27:45 PM »
This mod allows you to send emails from the 4images gallery via smtp with SSL authentication.

-----------| Changed Files |--------------------
/includes/email.php

-----------| New files |---------------------------
/includes/SendMailSmtpClass.php

-----------| Installation |-----------------------
Step 1

Download SendMailSmtpClass.php attached on this post and copy to /includes/SendMailSmtpClass.php

Step 2
Open /includes/email.php
Find:
Code: [Select]
if (!defined('ROOT_PATH')) {
  die("Security violation");
}

below insert:
Code: [Select]
require_once "SendMailSmtpClass.php"; // the plug-in class

Find:
Code: [Select]
  function send_email() {
    if ($this->use_smtp) {
      return ($this->smtp_mail($this->to, $this->subject, $this->body, $this->create_header())) ? 1 : 0;
    }
    else {
      return (mail($this->to, $this->subject, $this->body, $this->create_header())) ? 1 : 0;
    }

You can delete this function or comment on the code
Code: [Select]
/* ////////// Original function send_email //////////
    function send_email() {
    if ($this->use_smtp) {
      return ($this->smtp_mail($this->to, $this->subject, $this->body, $this->create_header())) ? 1 : 0;
    }
    else {
      return (mail($this->to, $this->subject, $this->body, $this->create_header())) ? 1 : 0;
    }
  } */

below insert:
Code: [Select]
// Mod Simple smtp ssl sending START
  function send_email() {
    global $config;
$sitename = $config['site_name'];          // the site name is taken from the gallery settings
$smtp_from = 'mygallery@gmail.com';        // sender's email and smtp login
$smtp_password = 'my_password_smtp_user';  // smtp user password
$smtp_host = 'ssl://smtp.gmail.com';       // smtp server address, do not delete the transport ssl://
$smtp_port = 465;                          // smtp port
$smtp_charset = "UTF-8";                   // encoding of email messages UTF-8 or windows-1251

$from = array( $sitename, $smtp_from);
$mailSMTP = new SendMailSmtpClass($smtp_from, $smtp_password, $smtp_host, $smtp_port, $smtp_charset);
return ($mailSMTP->send($this->to, $this->subject, $this->body, $from)) ? 1 : 0;
  }
// Mod Simple smtp ssl sending END

This is an example of settings for working with mail gmail.com
Change to your own parameters.

The "word_wrap"function also doesn't work well by default.
It inserts a break in the text of your emails in unexpected places.
To disable it find:
Code: [Select]
  var $word_wrap = 76;
Replace:
Code: [Select]
  var $word_wrap = 0;
Tested on mail servers yandex.ru, mail.ru and gmail.com, smtp.beget.com

Author SendMailSmtpClass.php - Ipatov Evgeniy admin@vk-book.ru
Article https://vk-book.ru/novaya-versiya-klassa-sendmailsmtpclass-otpravka-fajlov-cherez-smtp-s-avtorizaciej-po-protokolu-ssl-na-php/
This project on github - https://github.com/Ipatov/SendMailSmtpClass

By default, emails are sent as text, but the class supports sending in html format and even sending files.

Good luck! :)