How customer get mail after cash on delivery in magento

In Magento, when a customer places an order and selects "Cash on Delivery" (COD) as the payment method, the order is marked as "pending" and the customer is not charged immediately. The order is only confirmed when the customer pays the cash to the delivery person.

To send a confirmation email to the customer after they pay the cash, you need to configure the email template and the order status update in Magento. Here's a step-by-step guide:

Step 1: Create a custom order status

In Magento, you need to create a custom order status to track the order as "Paid" after the customer pays the cash. To do this:

  1. Log in to your Magento admin panel.
  2. Go to System > Configuration > Sales > Orders.
  3. Click on Add New Status.
  4. Enter a name for the new status, e.g., "Paid COD".
  5. Set the status as "Enabled" and click Save.

Step 2: Update the order status after payment

To update the order status to "Paid COD" after the customer pays the cash, you need to create a custom module. You can use the Magento's built-in sales_order_payment_cron cron job to achieve this.

Create a new file PaymentCron.php in the app/code/local/YourCompany/YourModule/Model directory:

<?php

namespace YourCompany\YourModule\Model;

use Magento\Sales\Model\Order;

class PaymentCron extends \Magento\Framework\Model\AbstractModel
{
    public function execute()
    {
        $orders = Mage::getModel('sales/order')->getCollection()
            ->addFieldToFilter('payment_method', 'cashondelivery')
            ->addFieldToFilter('status', 'pending')
            ->getItems();

        foreach ($orders as $order) {
            if ($order->getPayment()->getMethodInstance()->getCode() == 'cashondelivery') {
                $order->setStatus('paid');
                $order->save();
            }
        }
    }
}

This code retrieves all pending orders with the cash on delivery payment method and updates their status to "Paid COD" if the payment method is cash on delivery.

Step 3: Configure the email template

To send a confirmation email to the customer after the order is marked as "Paid COD", you need to configure the email template.

  1. Go to System > Configuration > Sales > Orders.
  2. Click on Emails.
  3. Click on Add New Template.
  4. Enter a name for the template, e.g., "COD Payment Confirmation".
  5. Set the template as "Enabled" and click Save.

In the template, you can add the following code to send a confirmation email to the customer:

{{template config_path="sales/email/order/paid"}}

This code will send the default "Order Paid" email template to the customer.

Step 4: Schedule the cron job

To schedule the cron job to run automatically, go to System > Configuration > Advanced > System.

  1. Click on Cron Jobs.
  2. Click on Add New Cron Job.
  3. Enter the following command: php /path/to/magento/bin/magento sales/order_payment_cron
  4. Set the schedule to run the cron job at a suitable interval, e.g., every hour.

After completing these steps, when a customer places an order with cash on delivery and pays the cash, the order status will be updated to "Paid COD", and a confirmation email will be sent to the customer.