0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PHP: Symfony Mailer の使い方

Posted at

こちらと同じことを、Symfony Mailer で行いました。
PHP: Swift Mailer の使い方

ライブラリーのインストール

composer require symfony/mailer

プログラム

ツリー構造

$ tree -L 2
.
├── composer.json
├── composer.lock
├── symfonymailer.php
└── vendor
    ├── autoload.php
    ├── composer
    ├── doctrine
    ├── egulias
    ├── psr
    └── symfony
symfonymailer.php
<?php

require_once 'vendor/autoload.php';
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;

// 送信設定
$from='user@hi-ho.ne.jp';
$to='user@example.com';
$mailer_dsn = 'smtp://user@hi-ho.ne.jp:password@hi-ho.mose-mail.jp:587';
$transport = Transport::fromDsn($mailer_dsn);
$mailer = new Mailer($transport);
$email = new Email();

$str_out = 'Hello,Everybody' . PHP_EOL;
$str_out .= 'Test' . PHP_EOL;
$str_out .= 'Dec/20/2023' . PHP_EOL;
$str_out .= 'Dec/20/2023' . PHP_EOL;
$str_out .= 'Dec/20/2023' . PHP_EOL;

$email
	->from($from)
	->to($to)
 	->subject('Time for Symfony Mailer!')
	->text($str_out)
       	;

// メール送信
$mailer->send($email);

送信

php symfonymailer.php

送信結果

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?