3

公式のSwiftMailerグループからのクロスポスト...

Swift Mailerバンドルとファイルスプールを使用してメールを送信しようとしていますが、コンソールにメールを送信するように指示すると、スプールにメッセージが0個あると表示されます。スプールはSwiftMailerによって自動的に作成されることになっていますか、それとも手動でファイルを作成する必要がありますか?スプールファイルがどこにも表示されないためです。

私のconfig.yml:

# Swiftmailer Configuration
swiftmailer:
    transport: sendmail
    host:      /usr/bin/sendmail
    username:  %mailer_user%
    password:  %mailer_password%
    spool:
        type: file
        path: "%kernel.root_dir%/spool"

メールの送信方法:

public function contactAction(Request $request)
{
    $form = $this->createFormBuilder()
        ->add('name', 'text', array('label' => 'Name:'))
        ->add('email', 'email', array('label' => 'Email Address:'))
        ->add('subject', 'text', array('label' => 'Subject:'))
        ->add('message', 'textarea', array('label' => 'Message:'))
        ->getForm();

    if ($request->isMethod('POST')) {
        $form->bind($request);
        $data = $form->getData();

        if (!empty($data['name'])) {
            $data['message'] = str_replace("\n.", "\n..", $data['message']);

            $emailValidator = new Email();
            $emailValidator->message = "Invalid email address";

            $error = $this->get('validator')->validateValue($data['email'], $emailValidator);

            if (count($error) == 0) {
                $mail = \Swift_Message::newInstance()
                    ->setSubject($data['subject'])
                    ->setFrom('mail@mysite.com')
                    ->setTo('me@myrealaddress.com')
                    ->setBody($data['message']);

                $this->get('mailer')->send($mail);

                return $this->redirect($this->generateUrl('_success'));
            } else {
                return $this->redirect($this->generateUrl('_failure'));
            }
        }
    }

私は何が間違っているのですか?Symfonyのドキュメントによると、これは機能しているはずです。

4

1 に答える 1

4

標準インストールでは、このディレクトリ内で作成および書き込みを行うのとpath: "%kernel.root_dir%/spool"同等であり、Webサーバーを実行しているユーザーには特定の権限が必要です。app/spool

ただし、ディレクトリのアクセス許可を変更したくない場合はcache、次の構成でいつでもフォルダを使用できます。

# Swiftmailer Configuration
swiftmailer:
    transport: sendmail
    host:      /usr/bin/sendmail
    username:  %mailer_user%
    password:  %mailer_password%
    spool:
        type: file
        path: "%kernel.cache_dir%/swiftmailer/spool"

そうすることで、キャッシュをクリアするときに本当に注意する必要があることに注意してください。未送信の電子メールがあると、他のキャッシュファイルと一緒に消えてしまうからです

于 2013-01-20T18:43:21.237 に答える