• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customization to override the built-in mail Library for better debugging during build

#1
I'm wondering if there is anything like Wordpress's WP Mail Logger in the Code Igniter world. Did some searching but couldn't come up with anything.
https://wordpress.org/plugins/wp-mail-logging/

Quite often when I am working on Wordpress sites, I will enable that. By simply being activeit will prevent mail from actually being sent out as well as keep record of the mails that had been attempted. I would love to also do this when I am building a custom application on CI.

Any input would be great. Thank you.
Reply

#2
You could create a MY_Email library that extends the Email class and change the send method to log the outgoing emails.
Create a config file so you can enable/disable the logging of emails.

Add some methods to write the messages to file or save them in a DB table.
Reply

#3
If I'm going to use email for a website, I always set up a mail queue in the database. Instead of sending email like you normally do, you instead put the contents of the email, and all the email params, in your database. Once a minute you have cron look for unsent emails, and after sending the emails are marked as sent. This allows you to look at emails if you need to, and the best thing is you can resend and email if necessary. This also removes the delay associated with sending an email during your site visitor's actions.

I set up my mail queue to use drivers. CI Email is one driver, but then I can also send via Swiftmailer. I only did that because at one point my host was saying that the CI Email class was the reason my emails would not send, so I had to prove it was not CI Email.
Reply

#4
Thanks for the input. I went ahead and made a custom MY_Email to add this in. It's only something intended for use during development, so pretty slimmed down (to, subject, body). I also have to replacing the native mail protocol so my local mail queue won't get clogged up, not to mention to avoid accidentally sending mail to my client while I'm testing.

Suggestions are always welcome.

https://github.com/louiswalch/CodeIgnite..._Email.php
Reply

#5
(06-23-2017, 11:16 AM)louiswalch Wrote: ... not to mention to avoid accidentally sending mail to my client while I'm testing.

You should check out mailtrap.io . You can send email with mailtrap's SMTP settings. It's great for dev, if that's all you need.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.