Giter VIP home page Giter VIP logo

silverstripe-smtp's Introduction

PHPMailer for SilverStripe

Based on http://silverstripe.org/smtpmailer-module/ but as it's outdated and not available on GitHub I created this fork.

Description

silverstripe-smtp automatically sends emails (e.g. from UserForms) to your provider's or host's SMTP server instead of using PHP's built-in mail() function.

silverstripe-smtp replaces the classic SilverStripe Mailer (using the mail() function) with PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer, was http://sourceforge.net/projects/phpmailer/) to send emails via the SMTP protocol to a local or remote SMTP server.

When would you use this module:

  • If your provider disabled mail()
  • If you have troubles sending emails because of the DNS configuration and the way some mail servers discard emails if the domain names don't match
  • If you want to send emails from your local web server without having to install a mail server, using an external SMTP server instead
  • If you want to send encrypted emails (using SSL or TLS protocols)
  • If you are using Amazon Web Services and would like to utilize the SES (Simple Email Service) which requires throttling and the use of SMTP with authentication over SSL/TLS.

Requirements

SilverStripe 2.3+

Installation

  1. Extract the silverstripe-smtp folder into the top level of your site and rename it to smtp
  2. Without any configuration, the module is going to connect to the mail server on localhost without authentication
  3. If you want to fall back to the classic mailer without uninstalling the module: Edit smtp/_config.php and comment out the set_mailer statement

Configuration

Configure the module by editing mysite/_config.php and set the following constants:

//Required:
define('SMTPMAILER_SMTP_SERVER_ADDRESS', 'smtp.gmail.com'); //SMTP server address
define('SMTPMAILER_DO_AUTHENTICATE', true); //Turn on SMTP server authentication. Set to false for an anonymous connection
define('SMTPMAILER_USERNAME', '[email protected]'); //SMTP server username, if SMTPAUTH == true
define('SMTPMAILER_PASSWORD', 'bar'); //SMTP server password, if SMTPAUTH == true

//Optional:
define('SMTPMAILER_CHARSET_ENCODING', 'utf-8'); //Email characters encoding, e.g. : 'utf-8' or 'iso-8859-1'
define('SMTPMAILER_USE_SECURE_CONNECTION', 'ssl'); //SMTP encryption method : Set to '', 'tls', or 'ssl'
define('SMTPMAILER_SMTP_SERVER_PORT', 465); //SMTP server port. Set to 25 if no encryption is used, 465 if ssl or tls is activated
define('SMTPMAILER_DEBUG_MESSAGING_LEVEL', 0); //Print debugging informations. 0 = no debuging, 1 = print errors, 2 = print errors and messages, 4 = print full activity
define('SMTPMAILER_LANGUAGE_OF_MESSAGES', 'de'); //Language for messages. Look into smtp/code/vendor/language/ for available languages
define('SMTPMAILER_SEND_DELAY', 2000);//throttling, in milliseconds, can also be 0

silverstripe-smtp's People

Contributors

clyonseis avatar icecaster avatar nicktacular avatar saiyan avatar swaibar avatar undefinedoffset avatar xeraa avatar xini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

silverstripe-smtp's Issues

Composer

Is a Packagist package in the near future for this? I have a few upgrades to do and want to avoid installing manually if so. Thanks!

Error when send massive emails (using silverstripe-newsletter module)

Hi, I got the problem that when I send a newsletter for 1000 emails, if in these emails has a bad email (such as: [email protected]), the smtp will throw the error to said that the sender is invalid. And then it cannot send any email.

I make some test and found that when the loop got the bad email, the next email send action is always throw this error:

The following From address failed: <my_email>

I tried with close the smtp every time it got error but not success

try {
        $this->buildBasicMail($to, $from, $subject);
        $customheaders['X-SMTPAPI'] = '{"category": "' . $_SERVER['HTTP_HOST'] . '"}'; // Add the current domain for services like SendGrid
        $this->addCustomHeaders($customheaders);
        $this->attachFiles($attachedFiles);
        $this->mailer->Send();

        if($this->mailer->SMTPDebug > 0){
            echo "<em><strong>*** E-mail to $to has been sent.</strong></em><br />";
            echo "<em><strong>*** The debug mode blocked the process</strong> to avoid the url redirection. So the CC e-mail is not sent.</em>";
            die();
        }

    } catch(phpmailerException $pe){
        $this->handleError($pe->errorMessage(), $msgForLog);
        $this->mailer->SmtpClose();
        throw $pe;
    } catch(Exception $e){
        $this->handleError($e->getMessage(), $msgForLog);
        $this->mailer->SmtpClose();
        throw $e;
    }

Could you please check the problem? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.