How to mail check in codeigniter

To mail a check in CodeIgniter, you can use the PHPMailer library, which is a popular and widely-used library for sending emails. Here's a step-by-step guide on how to do it:

Step 1: Install PHPMailer

You can install PHPMailer using Composer by running the following command:

composer require phpmailer/phpmailer

Step 2: Load the PHPMailer library in CodeIgniter

In your CodeIgniter controller, load the PHPMailer library by adding the following line:

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

Step 3: Configure PHPMailer

Configure PHPMailer by setting the following properties:

$this->phpmailer->isSMTP();
$this->phpmailer->Host = 'your_smtp_host';
$this->phpmailer->SMTPAuth = true;
$this->phpmailer->Username = 'your_smtp_username';
$this->phpmailer->Password = 'your_smtp_password';

Replace your_smtp_host, your_smtp_username, and your_smtp_password with your actual SMTP server details.

Step 4: Set the email details

Set the email details, including the sender's email address, recipient's email address, and the subject:

$this->phpmailer->setFrom('[email protected]', 'Sender Name');
$this->phpmailer->addAddress('[email protected]', 'Recipient Name');
$this->phpmailer->Subject = 'Check Payment';

Step 5: Attach the check file

Attach the check file to the email using the addAttachment() method:

$this->phpmailer->addAttachment('path/to/check.pdf', 'check.pdf');

Replace path/to/check.pdf with the actual path to the check file.

Step 6: Send the email

Send the email using the send() method:

if ($this->phpmailer->send()) {
    echo 'Email sent successfully!';
} else {
    echo 'Error sending email: '. $this->phpmailer->ErrorInfo;
}

That's it! With these steps, you should be able to mail a check in CodeIgniter using PHPMailer.

Here's the complete code example:

<?php

class CheckController extends CI_Controller {

    public function send_check() {
        $this->load->library('phpmailer');

        $this->phpmailer->isSMTP();
        $this->phpmailer->Host = 'your_smtp_host';
        $this->phpmailer->SMTPAuth = true;
        $this->phpmailer->Username = 'your_smtp_username';
        $this->phpmailer->Password = 'your_smtp_password';

        $this->phpmailer->setFrom('[email protected]', 'Sender Name');
        $this->phpmailer->addAddress('[email protected]', 'Recipient Name');
        $this->phpmailer->Subject = 'Check Payment';

        $this->phpmailer->addAttachment('path/to/check.pdf', 'check.pdf');

        if ($this->phpmailer->send()) {
            echo 'Email sent successfully!';
        } else {
            echo 'Error sending email: '. $this->phpmailer->ErrorInfo;
        }
    }

}

Make sure to replace the placeholders with your actual SMTP server details and check file path.