Skip to content

Commit

Permalink
base64に変更 その1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigehiro IDANI committed Dec 4, 2019
1 parent 91811b3 commit a3085a0
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/src/Controller/MailerController.php
Expand Up @@ -5,7 +5,9 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\Part\TextPart;
use Symfony\Component\Routing\Annotation\Route;

class MailerController extends AbstractController
Expand Down Expand Up @@ -38,19 +40,15 @@ public function index(MailerInterface $mailer)
この点で、フレームワークはブラックボックスではありません!Symfonyの場合、それはまだPHPです...開発されるアプリケーションはSymfonyユニバースに限定されず、たとえば他のPHPライブラリとネイティブに相互運用できます。
EOL;


$email = (new Email())
->from(new Address('hello@example.com', '送信者名'))
->to(new Address('you@example.com', '受信者名'))
//->cc('cc@example.com')
//->bcc('bcc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('日本語のサブジェクトになります。長くなると文字化けするという話もありますので、長く書いてみます。これぐらい長いとどうかな?')
->text($body)
// ->html('<p>See Twig integration for better HTML integration!</p>')
$headers = (new Headers())
->addMailboxListHeader('From', [new Address('hello@example.com', mb_encode_mimeheader('送信者名'))])
->addMailboxListHeader('To', [new Address('you@example.com', mb_encode_mimeheader('受信者名'))])
->addTextHeader(mb_encode_mimeheader('日本語のサブジェクトになります。長くなると文字化けするという話もありますので、長く書いてみます。これぐらい長いとどうかな?'))
;

$textContent = new TextPart($body, 'utf-8', 'plain', 'base64');
$email = new Message($headers, $textContent);

$mailer->send($email);

return $this->render('mailer/index.html.twig', [
Expand Down

0 comments on commit a3085a0

Please sign in to comment.