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

Swiftmailer Mail Wrapper #2

Open
sarelvdm opened this issue May 31, 2017 · 1 comment
Open

Swiftmailer Mail Wrapper #2

sarelvdm opened this issue May 31, 2017 · 1 comment
Labels

Comments

@sarelvdm
Copy link

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);
@fabriceyopa
Copy link
Owner

Hi @sarelvdm you can't fork the project, do it by your side and them pull request your modification. So i can't merge it to the master branch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants