symfony-mailer-example/mailer.php

27 lines
1.0 KiB
PHP
Raw Normal View History

2022-12-04 05:41:35 +00:00
<?php
require_once 'vendor/autoload.php';
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Email;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$dotenv->required(['MAILER_PREFIX','MAILER_PWD','MAILER_SUFFIX']);
$dotenv->required('MAILER_PREFIX')->notEmpty();
$dotenv->required('MAILER_PWD')->notEmpty();
$dotenv->required('MAILER_SUFFIX')->notEmpty();
$dsn = $_ENV['MAILER_PREFIX'] . urlencode($_ENV['MAILER_PWD']) . $_ENV['MAILER_SUFFIX'];
$transport = Transport::fromDsn($dsn);
// $pwd = urlencode('oALj/+F*b#).n&3i>{A>_x[nbk(k97~2');
// $transport = Transport::fromDsn('smtp://noreply@adamsdesk.com:' . $pwd . '@pariah.cirrushosting.com:465?verify_peer=0');
$mailer = new Mailer($transport);
$email = (new Email())
->from('Tester' . '<' . 'tester@example.com' .'>')
->to('hello@adamsdesk.com')
->subject('Contact Form Submission')
->text('Hello world, this is a test of the php email sender.');
$sendResult = $mailer->send($email);
?>