@parimal20 That's not the purpose of CC!
Jun 30, 2023
4
Level 1
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;
}
}
Please or to participate in this conversation.