php-swiftmailerHow to add CC to an email using Swiftmailer?
Adding CC to an email using Swiftmailer is a simple process.
Example code
$message = (new \Swift_Message('Hello World'))
->setFrom(['[email protected]' => 'John Doe'])
->setTo(['[email protected]', '[email protected]' => 'A name'])
->setCc(['[email protected]'])
->setBody('Here is the message itself')
;
The code above will add a CC to the email.
Code explanation
- \Swift_Message('Hello World') - creates a new Swift_Message object with the subject 'Hello World'
- setFrom(['[email protected]' => 'John Doe']) - sets the sender of the email
- setTo(['[email protected]', '[email protected]' => 'A name']) - sets the primary recipients of the email
- setCc(['[email protected]']) - sets the CC recipients of the email
- setBody('Here is the message itself') - sets the body of the email
Helpful links
More of Php Swiftmailer
- How to set timeout with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to get the response code when using Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to configure Swiftmailer for Postfix?
- How to send emails in UTF8 using Swiftmailer?
- How to send emails to multiple recipients with Swiftmailer?
- How to set the port for Swiftmailer?
- How to enable TLS with Swiftmailer?
See more codes...