How to integrate smtp mail in codeignator

To integrate SMTP mail in CodeIgniter, you can use the SMTP class provided by CodeIgniter. Here are the steps:

Step 1: Configure the SMTP settings

In your config.php file, add the following settings:

$config['smtp_host'] = 'your_smtp_host';
$config['smtp_user'] = 'your_smtp_username';
$config['smtp_pass'] = 'your_smtp_password';
$config['smtp_port'] = 587; // or 25, 465, etc.

Replace the placeholders with your actual SMTP server settings.

Step 2: Load the SMTP class

In your controller or model, load the SMTP class:

$this->load->library('smtp');

Step 3: Set the SMTP settings

Use the set_smtp_params() method to set the SMTP settings:

$this->smtp->set_smtp_params($config['smtp_host'], $config['smtp_user'], $config['smtp_pass'], $config['smtp_port']);

Step 4: Send the email

Use the send() method to send the email:

$this->smtp->send($to_email, $subject, $message);

Here's an example of how to send an email using the SMTP class:

<?php

class Email extends CI_Controller {

    public function send_email() {
        $this->load->library('smtp');

        $config = array(
            'smtp_host' => 'your_smtp_host',
            'smtp_user' => 'your_smtp_username',
            'smtp_pass' => 'your_smtp_password',
            'smtp_port' => 587
        );

        $this->smtp->set_smtp_params($config['smtp_host'], $config['smtp_user'], $config['smtp_pass'], $config['smtp_port']);

        $to_email = '[email protected]';
        $subject = 'Test Email';
        $message = 'This is a test email sent using CodeIgniter SMTP';

        $this->smtp->send($to_email, $subject, $message);

        echo 'Email sent successfully!';
    }
}

Note: Make sure to replace the placeholders with your actual SMTP server settings and email details.

That's it! With these steps, you should be able to integrate SMTP mail in your CodeIgniter application.