composer require pyataks/sendmail
$smtpConfig = [
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'username@gmail.com',
'password' => ''
];
$mandrillKey = 'mandrill API-key';
$mailer = new Mailer(new MailTransport());
try {
$message = (new Message())
->to('emailto@example.com', 'Jon')
->from('emailfrom@example.com', 'Jon Mailer')
->subject('Test subject. Send mail php')
->body('<div style="color: red">Test content. Send mail php</div>', 'text/html')
->attach('full_filename', ['name' => 'main-logo.png', 'mime_type' => 'image\png']);
} catch (\InvalidArgumentException $e) {
echo $e, PHP_EOL;
}
try {
echo $mailer->send($message);
} catch (\pyatakss\sendmail\PSMailException $e) {
echo $e, PHP_EOL;
}
$mailTransport = new MailTransport();
$smtpTransport = new SMTPTransport($smtpConfig);
$mandrillTransport = new MandrillTransport($mandrillKey);
$mailer = new Mailer($mailTransport);
$messageCyrillicText = (new Message())
->to('emailto1@example.com', 'Рома')
->to('emailto2@example.com', 'Маша')
->to('emailto3@example.com', 'Кирилл')
->from('emailfrom@example.com', 'Джон Сильвер')
->subject('Тема на кирилице. Send mail php')
->body('<div style="color: red">Текст письма.<br> Писмо отправелно без attach. <br> Send mail php</div>', 'text/html');
$messageSwift = (new SwiftMessageAdapter(new \Swift_Message()))
->to('emailto1@example.com', 'Рома')
->to('emailto2@example.com', 'Маша')
->to('emailto3@example.com', 'Кирилл')
->from('emailfrom@example.com', 'Джон Сильвер')
->subject('Subject English swift . Send mail php')
->body('<div style="color: green">Text of the letter.<br> Letter sent WITH attach. <br> Send mail php</div>', 'text/html')
->attach($listFiles[0])
->attach($listFiles[1]);
echo $mailer->send($messageCyrillicText);
$mailer->setTransport($smtpTransport);
$messageEnglish->subject('Subject English. Send smtp php');
echo $mailer->send($messageEnglish);