KEmail
Yii Application Component to interact with smtp servers without relying on PHP's mail or PEAR's Mail. Simply a wrapper for http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
Download from here Easiest way
Download from github https://github.com/mrkmg/KEmail Not easy, unless you are familiar with git
Copy KEmail into approot/protected/extenstions
Under "import", add:
application.extensions.KEmail.KEmail
Under "components", add:
'email'=>array(
'class'=>'KEmail',
'host_name'=>'smtp_server', //Hostname or IP of smtp server
),
Single recipient
Yii::app()->email->send('from@email.address','to@email.address','Subject','Body');
Multiple recipients
$to = array(
'user1@email.address',
'user2@emai.address',
);
Yii::app()->email->send('from@email.address',$to,'Subject','Body');
Full API Documentation on GITHUB
The following is an outline of all the avaible options, and their default options
host_name="localhost" Host name of smtp server
host_port=25 Port of smtp server
ssl=false Force SSL
http_proxy_host_name='' Set to enable using an http proxy to access smtp server
http_proxy_host_port=3128 Port of http proxy
socks_host_name='' Set to enable using a socks proxy
socks_host_port=1080 Port of socks proxy
socks_version='5' Version of socks proxy
start_tls=false Force `start_tls`
localhost='localhost' Given hostname of client
direct_delivery=false Skip smtp server and delevier directly to recipients smtp
timeout=10 Time in seconds to timeout for all smtp connections
data_timeout=0 Time in seconds to timeout for data transfer to SMTP server, if 0 uses timeout
debug=false Output Debug information to browser
html_debug=true Format Debug information as html
pop3_auth_host='' Set to authenticate to a pop3 server
user="" Username for smtp authentication
realm="" Realm for smtp authentication
password="" Password for smtp authentication
workstation="" Workstation for smtp authentication
authentication_mechanism="" Force a specific smtp authentication mechanism ('LOGIN','PLAIN','CRAM-MD5','NTLM')
enable_queue=false Enabled the queue
autocreate_db_table=true Check for and create if needed the queue table in the database
queue_table_name='kemail_queue' Name of the queue database table
For example, to send an HTML email, do the following
$headers = array(
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1'
);
Yii::app()->email->send('from@email.address','to@email.address','Subject','<html><head><title>Subject</title></head><body>BODY</body></html>',$headers);
In order to use the built in queue feature, you must have a database accessable via Yii::app()->db;
To Enable to queue, set the following options
'email'=>array(
'class'=>'KEmail',
'host_name'=>'smtp_server', //Hostname or IP of smtp server
'enable_queue'=>true, //This enabled to queue
),
autocreate_db_table should be set to false once the table has been created.
To queue an email, do the following
$headers = array(
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1'
);
$priority = 2; //INT between 0 and 9. Higher the number, the sooner it will be sent.
Yii::app()->email->queue('from@email.address','to@email.address','Subject','<html><head><title>Subject</title></head><body>BODY</body></html>',$headers,$priority);
Then, maybe via a cron script or by random chance,
Yii::app()->email->processQueue(5); //Process 5 emails out of the queue Yii::app()->email->processQueue(8,true) //Process 8 emails from the queue, and ignore priorities
Total 8 comments
Yes, I am still working on this project. Development is slow though. If you would like to help, feel free to clone the github project and send a pull request.
Is this extension still being updated? Error messages are desperately needed to log why an email failed other than a simple Boolean true/false.
You can add CC and BCC recipients via the headers.
For Example:
How to use CC and BCC??
The following setup works for GMAIL's smtp server
I sent you a PM on the forums. I have tried this on 3 different installations on different machines, and all of them worked perfect. My assumption is based on your error that you placed something in the config file in the wrong location.
I did the steps outlined.
I get this error:
Property "CWebApplication.email" is not defined.
Hi,
Any example on using GMail as SMTP?
Cheers,
Daniel
Leave a comment
Please login to leave your comment.