@aniya.jaskolski
To send an email using a template in CodeIgniter, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public function send_email() { $this->load->library('email'); // Set the email parameters $this->email->from('[email protected]', 'Your Name'); $this->email->to('[email protected]'); $this->email->subject('Email Subject'); // Set the email template $email_template = $this->load->view('email/template', '', TRUE); // Load the template file $this->email->message($email_template); // Set the template as the email message // Send the email if ($this->email->send()) { echo 'Email sent successfully.'; } else { echo 'Error sending email: ' . $this->email->print_debugger(); } } |
Here's an example of the template.php
file:
1 2 3 4 5 6 7 8 9 10 |
<html> <head> <title>Email Template</title> </head> <body> <h1>Hello, {{recipient_name}}!</h1> <p>This is a sample email template.</p> <p>Thank you for using our service.</p> </body> </html> |
In the template file, you can use placeholders like {{recipient_name}}
that will be replaced dynamically with data when sending the email.
Note: Make sure you have set the correct email configuration in the config
file and you have loaded the email
library before sending the email.