ivantcholakov / codeigniter-phpmailer Goto Github PK
View Code? Open in Web Editor NEWA CodeIgniter 3 compatible email-library powered by PHPMailer
License: MIT License
A CodeIgniter 3 compatible email-library powered by PHPMailer
License: MIT License
Is there a chance that You make an update to Phpmailer 6.06 - please !
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();
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();
attachment is not supported
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
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
Hi,
how can I embed image in body?
i got an error like this when send email, Message: fwrite(): send of 9 bytes failed with errno=32 Broken pipe
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
Please add sparks support, so it gets easier to integrate to an existing project easily.
Is it possible to add images to the html mail? if so, can you please add an example?
Many thanks in advance,
Amit
Hello.
There is an issue when using Eq. Google SMTP relay with authentication with server IP configured via G Suite configuration.
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.
I have to add this in phpMailer to solve this issue
$this->mail = new PHPMailer();
$this->mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
But how to do it in this library? Thanks.
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
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
The first link listed under Readings doesn't work anymore. Looks like the domain expired.
http://bisakomputer.com/membuat-pengiriman-email-terjadwal-dengan-framework-codeigniter/ - "Membuat Pengiriman Email Terjadwal dengan Framework CodeIgniter" by Arif Rachman, in Indonesian language.
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.
Can I add a list of recipient names with corresponding email list to cc and bcc to do so?
Sample code:
$ this-> email->cc (
array(
array('email' =>' [email protected]','name' => 'User 1'),
array('email' =>' [email protected]','name' => 'User 2'),
.....
)
)
$ this-> email->bcc (
array(
array('email' =>' [email protected]','name' => 'User 3'),
array('email' =>' [email protected]','name' => 'User 4'),
.....
)
)
Add a function to setup DKIM keys directly. http://stackoverflow.com/a/24464694
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.
$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?
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).
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->CI = get_instance();
Suggested by official user guide, it should be $this->CI =& get_instance();
Hey good day thank you for the awesome library integration to CI but i receive this error, when sending email.
bool(false)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
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]");
????
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?
wasted my 4 hours and totally of no use.
hi dear,
why this give me errors like this already configuration same like yours
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
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.
Codeigniter : 3.1.8
PHP : 5.6.8
OS: Win
php.ini
$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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.