Swift Mailer and Symfony2 - no mail in the reel

Cross-posting from Swift Mailer Official Group ....

I am trying to send emails using Swift Mailer package and file reel, but when I say the console is sending mail, it tells me that there are 0 messages in the reel. Is the coil supposed to be generated by Swift Mailer automatically or do I need to manually create the file? Because I don't see the spool file anywhere.

My 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"

      

How do I send mail:

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'));
            }
        }
    }

      

What am I doing wrong? According to the Symfony docs, this should work.

+3


source to share


1 answer


It is path: "%kernel.root_dir%/spool"

equivalent in a standard installation app/spool

, and the user using your web server needs certain permissions to create and write within this directory.

However, if you don't want to change the permissions in your directory, you can always use the folder cache

with the following configuration:



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

      

Please note that when doing this, you must be very careful when clearing your cache because if you have unsent emails, they will disappear with other cache files.

+4


source







All Articles