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 log emails sent with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to configure Swiftmailer for SMTP without authentication?
- Swiftmailer usage example
- How to send emails in UTF8 using Swiftmailer?
- How to set timeout with Swiftmailer?
- How to use Swiftmailer transport?
- How to set the 'from' address in Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
See more codes...