Code Monkey home page Code Monkey logo

codeigniter-phpmailer's Introduction

Latest Stable Version Total Downloads Latest Unstable Version License

A CodeIgniter compatible email-library powered by PHPMailer

Version: 1.5.0
Author: Ivan Tcholakov [email protected], 2012-2022.
License: The MIT License (MIT), http://opensource.org/licenses/MIT

This library is compatible with CodeIgniter 3.1.x and PHP >= 7.3.0.

Tested on CodeIgniter 3.1.13 (March 3rd, 2022) and PHPMailer Version 6.6.4 (August 22nd, 2022).

Links

Package: https://packagist.org/packages/ivantcholakov/codeigniter-phpmailer

PHPMailer: https://github.com/PHPMailer/PHPMailer

Installation

Enable Composer to be used by CodeIgniter. Check this page from its documentation: https://www.codeigniter.com/userguide3/general/autoloader.html . You need to see or decide when your vendor/ directory is (to be) and within the CodeIgniter's configuration file application/config/config.php you need to set the configuration option $config['composer_autoload'] accordingly. For the typical location application/vendor/ the configuration setting would look like this:

$config['composer_autoload'] = APPPATH.'vendor/autoload.php';

Within application/config/constants.php add the following lines:

// Path to Composer's vendor/ directory, it should end with a trailing slash.
defined('VENDORPATH') OR define('VENDORPATH', rtrim(str_replace('\\', '/', realpath(dirname(APPPATH.'vendor/autoload.php'))), '/').'/');

It is assumed that Composer's vendor/ directory is placed under CodeIgniter's application/ directory. Otherwise correct the setting so VENDORPATH to point correctly.

If PHPMailer was previously installed through Composer, uninstall it temporarily:

composer remove PHPMailer/PHPMailer

Now install this library's package, it will install a correct version of PHPMailer too:

composer require ivantcholakov/codeigniter-phpmailer

Create a file application/helpers/MY_email_helper.php with the following content:

<?php defined('BASEPATH') OR exit('No direct script access allowed.');

// A place where you can move your custom helper functions,
// that are to be loaded before the functions below.
// If it is needed, create the corresponding file, insert
// your source there and uncomment the following lines.
//if (is_file(dirname(__FILE__).'/MY_email_helper_0.php')) {
//    require_once dirname(__FILE__).'/MY_email_helper_0.php';
//}

// Instead of copying manually or through script in this directory,
// let us just load here the provided by Composer file.
if (is_file(VENDORPATH.'ivantcholakov/codeigniter-phpmailer/helpers/MY_email_helper.php')) {
    require_once VENDORPATH.'ivantcholakov/codeigniter-phpmailer/helpers/MY_email_helper.php';
}

// A place where you can move your custom helper functions,
// that are to be loaded after the functions above.
// If it is needed, create the corresponding file, insert
// your source there and uncomment the following lines.
//if (is_file(dirname(__FILE__).'/MY_email_helper_2.php')) {
//    require_once dirname(__FILE__).'/MY_email_helper_2.php';
//}

Create a file application/libraries/MY_Email.php with the following content:

<?php defined('BASEPATH') OR exit('No direct script access allowed.');

// Instead of copying manually or through script in this directory,
// let us just load here the provided by Composer file.
require_once VENDORPATH.'ivantcholakov/codeigniter-phpmailer/libraries/MY_Email.php';

This is an installation that is to be done once. Updating to next versions of this package and PHPMailer would be done later easily:

composer update

Configuration and Sending an E-mail (An Example)

Create if necessary or edit the file application/config/email.php which contains the default settings for the email engine. For a Gmail account, the setting might be something like this:

<?php defined('BASEPATH') OR exit('No direct script access allowed.');

$config['useragent']        = 'PHPMailer';              // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol']         = 'smtp';                   // 'mail', 'sendmail', or 'smtp'
$config['mailpath']         = '/usr/sbin/sendmail';
$config['smtp_host']        = 'smtp.gmail.com';
$config['smtp_auth']        = true;                     // Whether to use SMTP authentication, boolean TRUE/FALSE. If this option is omited or if it is NULL, then SMTP authentication is used when both $config['smtp_user'] and $config['smtp_pass'] are non-empty strings.
$config['smtp_user']        = '[email protected]';
$config['smtp_pass']        = '';                       // Gmail disabled the so-called "Less Secured Applications", your Google password is not to be used directly, XOAUTH2 authentication will be used.
$config['smtp_port']        = 587;
$config['smtp_timeout']     = 30;                       // (in seconds)
$config['smtp_crypto']      = 'tls';                    // '' or 'tls' or 'ssl'
$config['smtp_debug']       = 0;                        // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['debug_output']     = '';                       // PHPMailer's SMTP debug output: 'html', 'echo', 'error_log' or user defined function with parameter $str and $level. NULL or '' means 'echo' on CLI, 'html' otherwise.
$config['smtp_auto_tls']    = false;                    // Whether to enable TLS encryption automatically if a server supports it, even if `smtp_crypto` is not set to 'tls'.
$config['smtp_conn_options'] = array();                 // SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP.
$config['wordwrap']         = true;
$config['wrapchars']        = 76;
$config['mailtype']         = 'html';                   // 'text' or 'html'
$config['charset']          = null;                     // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.
$config['validate']         = true;
$config['priority']         = 3;                        // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see https://github.com/PHPMailer/PHPMailer/issues/449
$config['crlf']             = "\n";                     // "\r\n" or "\n" or "\r"
$config['newline']          = "\n";                     // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode']   = false;
$config['bcc_batch_size']   = 200;
$config['encoding']         = '8bit';                   // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.

// XOAUTH2 mechanism for authentication.
// See https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2
$config['oauth_type']          = 'xoauth2_google';      // XOAUTH2 authentication mechanism:
                                                        // ''                  - disabled;
                                                        // 'xoauth2'           - custom implementation;
                                                        // 'xoauth2_google'    - Google provider;
                                                        // 'xoauth2_yahoo'     - Yahoo provider;
                                                        // 'xoauth2_microsoft' - Microsoft provider.
$config['oauth_instance']      = null;                  // Initialized instance of \PHPMailer\PHPMailer\OAuth (OAuthTokenProvider interface) that contains a custom token provider. Needed for 'xoauth2' custom implementation only. 
$config['oauth_user_email']    = '';                    // If this option is an empty string or null, $config['smtp_user'] will be used.
$config['oauth_client_id']     = '237644427849-g8d0pnkd1jh3idcjdbopvkse2hvj0tdp.apps.googleusercontent.com';
$config['oauth_client_secret'] = 'mklHhrns6eF-qjwuiLpSB4DL';
$config['oauth_refresh_token'] = '1/7Jt8_RHX86Pk09VTfQd4O_ZqKbmuV7HpMNz-rqJ4KdQMEudVrK5jSpoR30zcRFq6';

// DKIM Signing
$config['dkim_domain']      = '';                       // DKIM signing domain name, for exmple 'example.com'.
$config['dkim_private']     = '';                       // DKIM private key, set as a file path.
$config['dkim_private_string'] = '';                    // DKIM private key, set directly from a string.
$config['dkim_selector']    = '';                       // DKIM selector.
$config['dkim_passphrase']  = '';                       // DKIM passphrase, used if your key is encrypted.
$config['dkim_identity']    = '';                       // DKIM Identity, usually the email address used as the source of the email.

Notes: Set $config['useragent'] as 'PHPMailer' in order PHPMailer engine to be used. PHP openssl module should be enabled if encrypted SMTP access is required.

Within a controller paste the following code for testing purposes:

$this->load->library('email');

$subject = 'This is a test';
$message = '
    <p>This message has been sent for testing purposes.</p>

    <!-- Attaching an image example - an inline logo. -->
    <p><img src="cid:logo_src" /></p>
';

// Get full html:
$body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=' . strtolower(config_item('charset')) . '" />
    <title>' . html_escape($subject) . '</title>
    <style type="text/css">
        body {
            font-family: Arial, Verdana, Helvetica, sans-serif;
            font-size: 16px;
        }
    </style>
</head>
<body>
' . $message . '
</body>
</html>';
// Also, for getting full html you may use the following internal method:
//$body = $this->email->full_html($subject, $message);

// Attaching the logo first.
$file_logo = FCPATH.'apple-touch-icon-precomposed.png';  // Change the path accordingly.
// The last additional parameter is set to true in order
// the image (logo) to appear inline, within the message text:
$this->email->attach($file_logo, 'inline', null, '', true);
$cid_logo = $this->email->get_attachment_cid($file_logo);
$body = str_replace('cid:logo_src', 'cid:'.$cid_logo, $body);
// End attaching the logo.

$result = $this->email
    ->from('[email protected]')
    ->reply_to('[email protected]')    // Optional, an account where a human being reads.
    ->to('[email protected]')
    ->subject($subject)
    ->message($body)
    ->send();

var_dump($result);
echo '<br />';
echo $this->email->print_debugger();

exit;

Load the corresponding page, executte this code. Check whether an email has been sent. Read the error message, if any, and make corrections in your settings.

Note, that most of the SMTP servers require "from" address of the message to be the same as the address within $config['smtp_user'] setting.

At the end remove this test.

The API of this library is the same as the original Email API. Read the CodeIgniter's manual about Email Class.

For supporting CodeIgniter 2.x and CodeIgniter 3.0.x a manual installation of an older version of this library is needed, see https://github.com/ivantcholakov/codeigniter-phpmailer/tree/1.3-stable

codeigniter-phpmailer's People

Contributors

bankde avatar isantolin avatar ivantcholakov avatar madurapa avatar synchro 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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-phpmailer's Issues

Why check for mailer_engine?

Throughout your library code you have many checks for mailer_engine like this:

if ($this->mailer_engine == 'phpmailer') {

Surely it's implicit in the fact that you're using this class that this will always be true, so all these checks are unnecessary?

I see there is a provision to use a different value in the constructor, but if that is the case, why would this class even be instantiated? If you want to use codeigniter as the mailer_engine, you'd just instantiate CI_Email and not MY_Email. If anything it looks like you're working around an upstream bug or limitation in CI - is that the case?

Phpmailer 6.06

Is there a chance that You make an update to Phpmailer 6.06 - please !

Error in Library MY_Email_3_0_x.php

When i run the controller which has your test code, It sends the mail and is working perfectly fine but the controller gives me this error. Can you please have a look ?

Severity: Warning

Message: Declaration of MY_Email::set_alt_message($str) should be compatible with CI_Email::set_alt_message($str = '')

Filename: libraries/MY_Email_3_0_x.php

Line Number: 0

Codeigniter Version: 2.2.6
PHP Version: 7.0

valid_email Error

I tried to use this library but I got the following error :
Fatal error: Call to undefined function valid_email() in C:\xampp\htdocs***\application\libraries\MY_Email.php on line 776

can not send email either

$config['useragent'] = 'PHPMailer'; // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol'] = 'sendmail'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'smtp.sina.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'xxxx';
$config['smtp_port'] = 25;
$config['smtp_timeout'] = 30; // (in seconds)
$config['smtp_crypto'] = ''; // '' or 'tls' or 'ssl'
$config['smtp_debug'] = 0; // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['smtp_auto_tls'] = true; // Whether to enable TLS encryption automatically if a server supports it, even if smtp_crypto is not set to 'tls'.
$config['smtp_conn_options'] = array(); // SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP.
$config['wordwrap'] = true;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html'; // 'text' or 'html'
$config['charset'] = null; // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.
$config['validate'] = true;
$config['priority'] = 3; // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see PHPMailer/PHPMailer#449
$config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r"
$config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode'] = false;
$config['bcc_batch_size'] = 200;
$config['encoding'] = '8bit'; // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.

// DKIM Signing
// See https://yomotherboard.com/how-to-setup-email-server-dkim-keys/
// See http://stackoverflow.com/questions/24463425/send-mail-in-phpmailer-using-dkim-keys
// See https://github.com/PHPMailer/PHPMailer/blob/v5.2.14/test/phpmailerTest.php#L1708
$config['dkim_domain'] = ''; // DKIM signing domain name, for exmple 'example.com'.
$config['dkim_private'] = ''; // DKIM private key file path.
$config['dkim_selector'] = ''; // DKIM selector.
$config['dkim_passphrase'] = ''; // DKIM passphrase, used if your key is encrypted.
$config['dkim_identity'] = ''; // DKIM Identity, usually the email address used as the source of the email.

i use "sendmail" send email not working , the same as smtp. on my computer. where can i see error log?

A PHP Error was encountered.

After the update to version 1.2.7 displays warning:
Message: Declaration of MY_Email::initialize($config = Array) should be compatible with CI_Email::initialize(array $config = Array)
Filename: libraries/MY_Email.php
Line Number: 0
Backtrace:
File: /srv/http/.../application/libraries/Aauth.php
Line: 112
Function: library
File: /srv/http/.../index.php
Line: 315
Function: require_once

I have:
PHP Version: 7.0.9
CodeIgniter 3.1.0
Codeigniter-phpmailer: 1.2.7

Authentication with server IP.

Hello.

There is an issue when using Eq. Google SMTP relay with authentication with server IP configured via G Suite configuration.

g-suite-smtp-relay-config

Consider this config:

$config['useragent']    = 'phpmailer'; // neither "codeigniter" works
$config['protocol']     = 'smtp';
$config['smtp_host']    = 'smtp-relay.gmail.com';
$config['smtp_user'] = '[email protected]';
// When using authentication with server IP, the password should be empty or false
$config['smtp_pass']    = '';
$config['smtp_port']    = '465';
$config['smtp_crypto'] = 'ssl';

When testing, the following error is thrown: Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted.

Actually, here the password and authentication is not required, it shouldn't require authentication, it just authenticates from the fact it's coming from an email associated with the domain name, and the IP address of the server.

The property boolean value _smtp_auth is set in a wrong way.

Take a look here:

https://github.com/ivantcholakov/codeigniter-phpmailer/blob/master/libraries/MY_Email_3_1_x.php#L704

https://github.com/ivantcholakov/codeigniter-phpmailer/blob/master/libraries/MY_Email_3_1_x.php#L720

In order this to work fine on line 704 should be:

$this->_smtp_auth = ($value != '' && $this->smtp_pass != '');

On line 720 should be:

$this->_smtp_auth = ($this->smtp_user != '' && $value != '');

I believe that this change won't break any current tests and implementation?

Regards.

The mail is not sending

Once I run this code, It display var_dump value "bool(true)". But the problem is the mail is not sending to the mail address I have given.

Even if I give a wrong password in smtp_pass it's showing the same - bool(true).

attach

attachment is not supported

images in html mail

Is it possible to add images to the html mail? if so, can you please add an example?
Many thanks in advance,
Amit

Unable to load the requested file: helpers/my_email_helper.php

Hi. Ive a problem to install PHPMailer with Codeigniter 3.
Ive put all the file correctly on the application folder.
Ive configured the email setting. But when I Go on the browser, I get this "Unable to load the requested file: helpers/my_email_helper.php". Help, please.

Return Path

Dear Ivan, as you maybe know, its not possible to set Return-path header on SMTP protocol in email class of codeigniter. Do you think it would be possible to do when we replace it with your lib? Syntax will be the same?

$this->email->reply_to("[email protected]","Sender Name","[email protected]");

????

Renaming attached file not working.

Hi, I'm trying to renaming attached file, but it's not working.

in MY_Email.php
at line 507:

$newname = basename($file); 

it works if I changed to:

$newname = basename($newname); 

Thanks

{unwrap} left in email

Had the codeigniter {unwrap} & {/unwrap} tags in my emails. They did not get removed. I could not find any phpmailer equivalent. The easiest solution (apart from not using them, which was not an option for me) was to just remove them by amending line 305 from:
$this->phpmailer->Subject = (string) $subject;
to:
$this->phpmailer->Subject = str_replace(array('{unwrap}', '{/unwrap}'), '', (string) $subject);

And line 321 from:
$this->phpmailer->Body = $body;
to:
$this->phpmailer->Body = str_replace(array('{unwrap}', '{/unwrap}'), '', $body);

This is for CI 2. Not sure how it applies to to CI 3.

$this->email->from name Error

I am using CodeIgniter 2.2.1, When i tries to send mails Using GMail PHPMailer config profile and defines From Name in the controller, justs shows me "Root User" instead "Este es el nombre"

config/email.php

$config['mailfrom'] = '[email protected]';

$config['useragent'] = 'PHPMailer';              // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol'] = 'smtp';                   // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'xxxx';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;                        // (in seconds)
$config['smtp_crypto'] = 'ssl';                    // '' or 'tls' or 'ssl'
$config['smtp_debug'] = 0;                        // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['wordwrap'] = true;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';                   // 'text' or 'html'
$config['charset'] = 'utf-8';
$config['validate'] = true;
$config['priority'] = 3;                        // 1, 2, 3, 4, 5
$config['crlf'] = "\n";                     // "\r\n" or "\n" or "\r"
$config['newline'] = "\n";                     // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode'] = false;
$config['bcc_batch_size'] = 200;
$config['encoding'] = '8bit';                   // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.

and calls the code from a controller

$subject = 'Este es el Mail de Registracion';
 $name = "Este es el nombre";
$message = "Message";


                $this->email->set_mailtype("html");
                $this->email->from($this->config->item('mailfrom'), $name);
                $this->email->reply_to($this->config->item('mailfrom'));
                $this->email->to($this->input->post('Email'));
                $this->email->subject($subject);
                $this->email->message($message);
                $this->email->send();

Use of undefined constant VENDORPATH

A PHP Error was encountered
Severity: Warning

Message: Use of undefined constant VENDORPATH - assumed 'VENDORPATH' (this will throw an Error in a future version of PHP)

Filename: helpers/MY_email_helper.php

Line Number: 13

Backtrace:

File: C:\xampp7.3.7\htdocs\s3\S3\application\helpers\MY_email_helper.php
Line: 13
Function: _error_handler

File: C:\xampp7.3.7\htdocs\s3\S3\application\controllers\Txts.php
Line: 6
Function: __construct

File: C:\xampp7.3.7\htdocs\s3\S3\index.php
Line: 315
Function: require_once

SMTP connect() failed

Codeigniter : 3.1.8
PHP : 5.6.8
OS: Win

php.ini

  • Enable : php_openssl.dll

Email

  • 2-Step Verification : Disable
  • Allow less secure apps: ON
$config['useragent']        = 'PHPMailer';              // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol']         = 'smtp';                   // 'mail', 'sendmail', or 'smtp'
$config['mailpath']         = '/usr/sbin/sendmail';     
$config['smtp_host']        = 'smtp.gmail.com';         // smtp.googlemail.com
$config['smtp_auth']        = true;                     // Whether to use SMTP authentication, boolean TRUE/FALSE. If this option is omited or if it is NULL, then SMTP authentication is used when both $config['smtp_user'] and $config['smtp_pass'] are non-empty strings.
$config['smtp_user']        = 'gmail_account';
$config['smtp_pass']        = 'gmail_password';
$config['smtp_port']        = 465;
$config['smtp_timeout']     = 30;                       // (in seconds)
$config['smtp_crypto']      = 'ssl';                      // '' or 'tls' or 'ssl'
$config['smtp_debug']       = 2;                        // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['debug_output']     = '';                       // PHPMailer's SMTP debug output: 'html', 'echo', 'error_log' or user defined function with parameter $str and $level. NULL or '' means 'echo' on CLI, 'html' otherwise.
$config['smtp_auto_tls']    = true;                    // Whether to enable TLS encryption automatically if a server supports it, even if `smtp_crypto` is not set to 'tls'.
$config['smtp_conn_options'] = array();                 // SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP.
$config['wordwrap']         = true;
$config['wrapchars']        = 76;
$config['mailtype']         = 'html';                   // 'text' or 'html'
$config['charset']          = 'UTF-8';                     // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.
$config['validate']         = true;
$config['priority']         = 3;                        // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see https://github.com/PHPMailer/PHPMailer/issues/449
$config['crlf']             = "\n";                     // "\r\n" or "\n" or "\r"
$config['newline']          = "\n";                     // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode']   = false;
$config['bcc_batch_size']   = 200;
$config['encoding']         = '8bit'; 

but showing error

2018-06-09 04:51:29 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
bool(false) 
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

why?

Sign-in attempt prevented

While using your application with following configuration:

<?php defined('BASEPATH') OR exit('No direct script access allowed.');

$config['useragent']        = 'PHPMailer';              // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol']         = 'smtp';                   // 'mail', 'sendmail', or 'smtp'
$config['mailpath']         = '/usr/sbin/sendmail';
$config['smtp_host']        = 'smtp.gmail.com';
$config['smtp_user']        = '[email protected]';
$config['smtp_pass']        = 'xx';
$config['smtp_port']        = 465;
$config['smtp_timeout']     = 30;                       // (in seconds)
$config['smtp_crypto']      = 'ssl';                       // '' or 'tls' or 'ssl'
$config['smtp_debug']       = 0;                        // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['smtp_auto_tls']    = false;                     // Whether to enable TLS encryption automatically if a server supports it, even if `smtp_crypto` is not set to 'tls'.
$config['smtp_conn_options'] = array();                 // SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP.
$config['wordwrap']         = true;
$config['wrapchars']        = 76;
$config['mailtype']         = 'html';                   // 'text' or 'html'
$config['charset']          = null;                     // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.
$config['validate']         = true;
$config['priority']         = 3;                        // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see https://github.com/PHPMailer/PHPMailer/issues/449
$config['crlf']             = "\n";                     // "\r\n" or "\n" or "\r"
$config['newline']          = "\n";                     // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode']   = false;
$config['bcc_batch_size']   = 200;
$config['encoding']         = '8bit';                   // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.

// DKIM Signing
// See https://yomotherboard.com/how-to-setup-email-server-dkim-keys/
// See http://stackoverflow.com/questions/24463425/send-mail-in-phpmailer-using-dkim-keys
// See https://github.com/PHPMailer/PHPMailer/blob/v5.2.14/test/phpmailerTest.php#L1708
$config['dkim_domain']      = '';                       // DKIM signing domain name, for exmple 'example.com'.
$config['dkim_private']     = '';                       // DKIM private key file path.
$config['dkim_selector']    = '';                       // DKIM selector.
$config['dkim_passphrase']  = '';                       // DKIM passphrase, used if your key is encrypted.
$config['dkim_identity']    = '';                       // DKIM Identity, usually the email address used as the source of the email.

I got the following issue in my email:


    Sign-in attempt prevented   
Hi xx,
Someone just tried to sign in to your Google Account [email protected] from an app that doesn't meet modern security standards.
Details:

We strongly recommend that you use a secure app, like Gmail, to access your account. All apps made by Google meet these security standards. Using a less secure app, on the other hand, could leave your account vulnerable. Learn more.

Google stopped this sign-in attempt, but you should review your recently used devices:

REVIEW YOUR DEVICES NOW
Best,
The Google Accounts team

Solution was to follow the link: https://www.google.com/settings/security/lesssecureapps and turned on for less secure apps.

Still wondering is it right approach? There might be security issues too.

mail->attach() doesnt work for me

Hey,

i like the repo a lot but i have a problem with attaching files to my email.

    $this->email
            ->from(email_sender)
            ->to(email_receiver)
            ->subject(email_subject)
            ->message(email_body)
            ->attach($_SERVER["DOCUMENT_ROOT"]."somefolder/".$attachments);

I checked if the path is wrong, but i cant find my error here. Some advice would be realy cool.

Add a method to set explicitly the body encoding

I don't know if it is an enhancement request or if I am doing wrong.

I use your wrapper because I have difficulties to use CI mail lib with an HTML body containing Khmer characters (see example below).

The only way I've found to make it work is to explicitly use quoted-printable for Encoding property. The Subject and From parts are correctly encoded but not the Body without this trick.

However your wrapper forbids to use the property $phpmailer which is protected. I patched your code with a quick and dirty fix, but I think others will benefit from a small improvement of your wrapper. Of course, I can be wrong and maybe that there is another way that I didn't understand.

<?php
echo "Start<br />\n";
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->setFrom('[email protected]', 'ប្រភេទនៃការសុំច្បាប់');
$mail->addAddress('[email protected]');
$mail->WordWrap = 70;
$mail->CharSet  = 'UTF-8';
$mail->Encoding = 'quoted-printable';
$mail->XMailer  = 'Test';
$mail->IsHTML(true);
$message = '<html><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"><meta charset="UTF-8"></head><body>test: <ul><li>ប្រភេទឈប់សម្រាកបានធ្វើអោយទាន់សម័យដោយជោគជ័យ</li></ul></body></html>';
$mail->Subject = 'Khmer - ប្រភេទនៃការសុំច្បាប់';
$mail->Body = $message;
$mail->send();

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.