PHP code example of webiny / mailer

1. Go to this page and download the library: Download webiny/mailer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webiny / mailer example snippets


class MyClass
{
    use \Webiny\Component\Mailer\Bridge\MailerTrait;

	function sendEmail() {
		// get the Mailer instance
		$mailer = $this->mailer('Default');

		// let's build our message
		$msg = $mailer->getMessage();
		$msg->setSubject('Hello email')
			->setBody('This is my test email body')
			->setTo(new Email('[email protected]', 'Jack'));

		// send it
		$mailer->send($msg);
	}
}

class MyClass
{
	use \Webiny\Component\Mailer\Bridge\MailerTrait;

	function sendEmail() {
		// get the Mailer instance
		$mailer = $this->mailer('Default');


		// let's build our message
		$msg = $mailer->getMessage();
		$msg->setSubject('Hello email')
			 ->setBody('Hi {name},
						   This is your new password: <strong>{password}</strong>.')
			 ->setTo([
					new Email('[email protected]'),
					new Email('[email protected]')
					]);

		// before sending, let's define the decorator replacements
		$replacements = [
			'[email protected]' => [
				'name'     => 'Jack',
				'password' => 'seCre!'
			],

			'[email protected]' => [
				'name'     => 'Sara',
				'password' => 'Log!n'
			]
		];
		$mailer->setDecorators($replacements);

		// send it
		$mailer->send($msg);
	}
}
yaml
    Mailer:
        Default:
            CharacterSet: utf-8
            MaxLineLength: 78
            Priority: 2
            Sender:
                Email: [email protected]
                Name: Nikola Tesla
            Transport:
                Type: smtp
                Host: smtp.gmail.com
                Port: 465
                Username: [email protected]
                Password: ***
                Encryption: ssl
                AuthMode: login
            AntiFlood:
                Threshold: 99
                Sleep: 1
            DisableDelivery: false
        Mandrill:
            Mode: template # template or html
            ApiKey: yourApiKey
            DisableDelivery: false
            Message:    # these are all optional
                FromEmail: ''
                FromName: ''
                Headers: []
                Important: false
                TrackOpens: null
                TrackClicks: null
                AutoText: null
                AutoHtml: null
                InlineCss: null
                UrlStripQs: null
                PreserveRecipients: null
                ViewContentLink: null
                BccAddress: ''
                TrackingDomain: null
                SigningDomain: null
                ReturnPathDomain: null
                Merge: true
                MergeLanguage: mailchimp
                Tags: []
                Subaccount: null
                GoogleAnalyticsDomains: []
                GoogleAnalyticsCampaign: ''
                Metadata: []
                RecipientMetadata: []
                Attachments: []
        Sendgrid:
            ApiUser: yourApiUser
            ApiKey: yourApiKey
            DisableDelivery: false
            Decorators:
                Wrapper: ['*|', '|*']