1. Go to this page and download the library: Download yii1tech/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/ */
use Symfony\Component\Mime\Email;
$email = (new Email())
->addFrom('[email protected]')
->addTo('[email protected]')
->subject('Greetings')
->text('Welcome to our application')
->html('<h1>Welcome to our application</h1>');
Yii::app()->mailer->send($email);
use yii1tech\mailer\TemplatedEmail;
$email = (new TemplatedEmail())
->addFrom('[email protected]')
->addTo('[email protected]')
->subject('Greetings')
->textTemplate('greetings-text') // Text Body will be set as render of 'views/mail/greetings-text.php'
->htmlTemplate('greetings-html') // HTML Body will be set as render of 'views/mail/greetings-html.php'
->context([
'name' => 'John Doe', // variables, which will be available inside the templates
]);
Yii::app()->mailer->send($email); // actual rendering takes place just before the sending
use Symfony\Component\Mime\Email;
class MailTest extends TestCase
{
public function testMail(): void
{
// code under test here
/** @var \yii1tech\mailer\transport\ArrayTransport $transport */
$transport = Yii::app()->mailer->getTransport();
// retrieve the last sent email message:
$sentMessage = $transport->getLastSentMessage();
$this->assetNotNull($sentMessage);
$this->assertSame('[email protected]', $sentMessage->getTo()[0]->getAddress());
// ...
// retrieve the all sent email messages. matching the callback condition:
$messages = $transport->filterSentMessages(function (Email $message) {
return $message->getSubject() === 'Greetings';
});
$this->assertCount(1, $messages);
// ...
}
}
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.