Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Parimal20's avatar

How to send different email content to all CC recipient in single email?

I am working on a project and I need assistance with a specific requirement. I am trying to send an email to multiple CC (carbon copy) recipients. I need each CC recipient to receive different email content. Currently, I am able to send the same email content to all recipients, but I haven't been able to figure out how to send different content to each CC recipient. Any insights, suggestions, or sample code would be greatly appreciated. Thank you in advance for your help!

Code are as below:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class AdvanceRequestUpdateEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $toEmails;
    public $ccEmails;
    public $allocationManager;
    public $advanceRequest;
    public $projectsDetails;
    public $requestedBy;
    public $processByAdmin;

    public function __construct($advanceRequest, $allocationManager, $projectsDetails = '', $toEmails, $ccEmails, $requestedBy, $processByAdmin)
    {
        $this->allocationManager = $allocationManager;
        $this->advanceRequest = $advanceRequest;
        $this->projectsDetails = $projectsDetails;
        $this->toEmails = $toEmails;
        $this->ccEmails = $ccEmails;
        $this->requestedBy = $requestedBy;
        $this->processByAdmin = $processByAdmin;
    }

    public function build()
    {
        if($this->processByAdmin === true){
            $email = $this->view('emails.advancerequestadminupdate')
            ->subject('PMS -  Update on Advance Request')
            ->with(['advanceRequest' => $this->advanceRequest, 'requestedBy' => $this->requestedBy, 'allocationManager' => $this->allocationManager, 'projectsDetails' => $this->projectsDetails]);
        }
        elseif($this->processByAdmin === false){
            $email = $this->markdown('emails.advancerequestupdate')
            ->subject('PMS - Update on Advance Request')
            ->with([
                'advanceRequest' => $this->advanceRequest,
                'requestedBy' => $this->requestedBy,
                'allocationManager' => $this->allocationManager,
                'projectsDetails' => $this->projectsDetails,
            ]);
        }

        
        foreach ($this->toEmails as $toEmail => $toName) {
            $email->to($toEmail, $toName);
        }

        foreach ($this->ccEmails as $ccEmail => $ccName) {
            // Check if the current CC email matches the specific email you want to add a paragraph for
            if ($ccEmail === '[email protected]') {
                $email->cc($ccEmail, $ccName)->view('emails.cc_recipient_view');
            } else {
                // Use the common view for other CC recipients
                $email->cc($ccEmail, $ccName);
            }
        }

        return $email;
  
    }
}
0 likes
4 replies
martinbean's avatar

@parimal20 You can’t. CC addressees receive a carbon copy of the email.

If you want to send different content to different recipients, then you need to send individual messages to each recipient.

Please or to participate in this conversation.