Example of send email method with using Swift_Mailer (Swift_SmtpTransport, Swift_Message)
If you want get Delivery/Failures/Errors Status you can use this construction:
/** * Method for sending emails via Swift_Mailer * @param $email - object * example $email = \new StdClass(); * $email->login = 'sender@mail.example'; * $email->password = 'password_of_sender_email'; * $email->host = 'imap.gmail.com'; //real example for Gmail * $email->first_name = 'Test Example Name'; * $email->to = 'reciepient@mail.example'; //or array ['reciepient1@mail.example','reciepient2@mail.example','reciepient3@mail.example'] * $email->subject = 'Example of subject'; * $email->body = 'Example of <br/> email body message'; * @return boolean */ public static function sendEmail($email) { $isSent = $failures = false; try { $transport = \Swift_SmtpTransport::newInstance()->setHost($email->host)->setPort(465)->setUsername($email->login)->setPassword($email->password)->setEncryption('ssl'); $mailMessage = \Swift_Message::newInstance()->setFrom([$email->login => $email->first_name])->setReturnPath($email->to)->setTo($email->to)->setSubject($email->subject)->setBody($email->body, 'text/html'); $mailer = \Swift_Mailer::newInstance($transport); if ($mailer->send($mailMessage, $failures)) { $isSent = true; echo ' SUCCESS SENDING!:' . $email->login . ' to ' . $email->to; } else { echo ' SENDING ERROR TO :' . print_R($failures); } } catch (\Exception $e) { echo 'Catch Error with ' . $email->login . ' : ' . $e->getErrorMessage() . "\n"; } return $isSent; }
swift_SmtpTransport / Swift_Message /Swift_Mailer