True to form, sending email through Code Igniter is a process reduced to feeding its email class with some typical parameters, such the email’s sender, the message’s subject, the corresponding text, and so forth. Of course, this has to be done by using the MVC pattern, therefore I’m going to define a controller class that sends email in a truly simple fashion. The signature of this controller is listed below. Take a look at it, please: class Email extends Controller{ function Email(){ // load controller parent parent::Controller(); $this->load->library('email'); } function index(){ // set email class parameters $this->email->from('me@domain.com','Alejandro Gervasio'); $this->email->to('you@domain.com'); $this->email->cc('migirlfriend@domain.com'); $this->email->bcc('myothergirlfriend@domain.com'); $this->email->subject('Testing email class'); $this->email->message('How are you, buddy?'); $data['title']='Sending email...'; $data['header']='Sending email now...'; $data['message']=$this->email->send()?'Message was sent successfully!':'Error sending email!'; $this->load->view('email_view',$data); } } As you can see, the above “Email” controller class presents a structure similar to the examples developed in previous tutorials. First, its constructor loads the corresponding email class via a loader object, so it can be used at a later time. Then, the “index()” method sets a few conventional parameters, which are used to send the email message, and finally dispatches the message via the “send()” method. Also, you should notice that the controller uses a view to display an error message or a simple confirmation of whether or not the email has been successfully sent. That was really simple to follow, wasn’t it? Now that you have learned how to use Code Igniter to send email messages very easily, it’s time to see how to code the previous view file, which will print on screen an indicative message. To learn how this view file will be created, please click on the link that appears below and keep up reading.
blog comments powered by Disqus |
|
|
|
|
|
|
|