Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Swiftmailer Mail Wrapper #2

@sarelvdm

Description

@sarelvdm

Hi,
Swiftmailer Mail Wrapper, will work with "swiftmailer/swiftmailer": "~5",
Im not sure if you already done some work on a mail wrapper, if not please consider this

Add content to app/config/container.php

use App\Helpers\SEmail;
SEmail::class => function (ContainerInterface $container) {
                return new SEmail();
            },

Add content to app\Helpers\SEmail.php

namespace App\Helpers;
use function DI\get;

class SEmail {
    protected $transport;
    protected $mailer;

    public function __construct() {

        $this->transport = \Swift_SmtpTransport::newInstance('mail.aaaa.com, 587)
                ->setUsername('')
                ->setPassword('');
        $this->mailer = \Swift_Mailer::newInstance($this->transport);
    }
    public function sendEmail($emails = "", $from = "", $subject = "", $body = "") {

        $message = \Swift_Message::newInstance();

        //$message->setTo($emailList);
        $message->setContentType('text/html');
        $message->setFrom($from);
        $message->setSubject($subject);
        $message->setBody($body);

        try {
//	    $message->setTo(explode(', ', $rec_Email));
            $message->setTo($emails);

            if (!$this->mailer->send($message, $failures)) {
                echo "Failures:";
                print_r($failures);
            } else {
                $numSent = + 1;
                printf("Sent %d messages\n", $numSent);
            }
        } catch (Swift_RfcComplianceException $e) {

            printf("Error %d messages\n", $numSent);
            Logger::newMessage($e);
        }
    }
}

To Execute…

use App\Helpers\SEmail as SEmail;
$subj = $view->fetch('email/message.twig', []);
$SEmail->sendEmail("to@emailadr", "noreply@,,,,,", "my subject view", $subj);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions