CodeIgniter send SMTP Gmail

18,197

I have used a test Gmail account for non-production CodeIgniter email testing, but when I deploy to the production server I use the ENVIRONMENT constant to detect the correct mail connection settings.

For Gmail, I found these configuration settings (which I have put in /application/config/email.php) work fine:

    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => '<test-account-name>@gmail.com',
      'smtp_pass' => '<test-account-password>',
    );

Your emails will most likely be marked as spam by the recipients email, until they white list your sender.

And FWIW, don't edit core CodeIgniter files, you can supply your connection details a number of different ways.

Share:
18,197
Muhyee
Author by

Muhyee

Updated on June 04, 2022

Comments

  • Muhyee
    Muhyee almost 2 years

    Hey guys I'm trying to create a reset password for this forum I'm developing.... Anyway I followed a bunch of guides and tried many versions of what you will see and this is the one with the least errors.... Still I can't figure out what's wrong, I could use your help please.

    class CI_Email {  //in library email.php
    
    var $useragent      = "CodeIgniter";
    var $mailpath       = "/usr/sbin/msmtp";    // Sendmail path
    var $protocol       = "smtp";   // mail/sendmail/smtp
    var $smtp_host      = "smtp.googlemail.com";        // SMTP Server.
    var $smtp_user      = "[email protected]";       // SMTP Username
    var $smtp_pass      = "mypass";     // SMTP Password
    var $smtp_port      = "465";        // SMTP Port
    var $smtp_timeout   = 5;        // SMTP Timeout in seconds
    var $smtp_crypto    = "";       // SMTP Encryption. Can be null, tls or ssl.
    var $mailtype       = "html";   // text/html  Defines email formatting
    var $charset        = "utf-8";  // Default char set: iso-8859-1 or us-ascii
    

    And this is the result:

    hello: 
    The following SMTP error was encountered: 
    Failed to send AUTH LOGIN command. Error: 
    from: 
    The following SMTP error was encountered: 
    to: 
    The following SMTP error was encountered: 
    data: 
    The following SMTP error was encountered: 

    The following SMTP error was encountered: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. Content-Type: multipart/alternative; boundary="B_ALT_51cd96f2daf24"

    This is a multi-part message in MIME format. Your email application may not support this format.

    --B_ALT_51cd96f2daf24 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit

    My text here...

    --B_ALT_51cd96f2daf24 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

    I also tried a lot of other config i found online such as:

        var $mailpath      = "/usr/sbin/sendmail";    // Sendmail path 
        var $smtp_host     = "ssl://smtp.googlemail.com";        // SMTP Server.
    

    or:

        var $mailpath      = "/usr/sbin/sendmail";    // Sendmail path
        var $smtp_host     = "ssl://smtp.gmail.com";        // SMTP Server.
    

    With SSL protocol in smtp_host I was getting an endless screen of countless errors.