Wednesday, February 14, 2018
Send Email In CodeIgniter With SMTP
Send Email In CodeIgniter With SMTP
Send Email In CodeIgniter With SMTP
T
hese days, almost every PHP framework supports a well developed email management library. CodeIgniter is no different as it has a great email sending class that ensures that CodeIgniter projects could send emails without difficulty.
In this article, I will describe how to send emails in a CodeIgniter application using SMTP. I will use the well known and maintained email sending class.
You might be interested in: How To Create A REST API In CodeIgniter
Load CodeIgniter�s Email Class
First, load the CodeIgniter�s email library through the following code snippet:
1 | $this->load->library(email); |
Set Email Parameters
The next step is to setup the required fields for the custom email. these fields could be setup through several functions including: from() function takes two parameters � the email address of the sender and the name. to() function takes the email address of the recipient. Next two functions are subject() and message() that round up the requirements for sending emails. Here is how these functions are used in the code:
1 2 3 4 | $this->email->from(email@example.com, Identification); $this->email->to(emailto@example.com); $this->email->subject(Send Email Codeigniter); $this->email->message(The email send using codeigniter library); |
Once these functions are filled, the final step is to send the email by using the send() function.
1 | $this->email->send(); |
Create the Controller
Create a controller file Sendingemail_controller.php and save it in the application/controller/. Add the following code to this file:
link download
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.