pyataks / sendmail
Send messages for the different ways.
1.0.8
2016-08-30 08:55 UTC
Requires
This package is not auto-updated.
Last update: 2024-12-15 09:08:08 UTC
README
Install
composer require pyataks/sendmail
Examples
SMTP configuration
$smtpConfig = [ 'host' => 'ssl://smtp.gmail.com', 'port' => 465, 'username' => 'username@gmail.com', 'password' => '' ];
Mandrill configuration
$mandrillKey = 'mandrill API-key';
Send message with attach through the mail()
$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; }
Create different transports
$mailTransport = new MailTransport(); $smtpTransport = new SMTPTransport($smtpConfig); $mandrillTransport = new MandrillTransport($mandrillKey);
Create transport for the mail()
$mailer = new Mailer($mailTransport);
Prepare messages
$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]);
Sending through mail
echo $mailer->send($messageCyrillicText);
Change transport to SMTP, change subject of prepared mail, and, finally, send
$mailer->setTransport($smtpTransport); $messageEnglish->subject('Subject English. Send smtp php'); echo $mailer->send($messageEnglish);