0

I'm developing on Symfony3. I have a command which allows to send a e-mail the first day of each month. When I was working on local, the command worked fine. Last week, I deploy my project in a "shared OVH Hosting", and when I execute the command, I get this error :

  [Symfony\Component\Debug\Exception\ContextErrorException]
  Warning: mkdir(): Permission denied

This is my swiftmailer configuration : (config.yml) :

swiftmailer:
    transport: "%mailer_transport%"
    auth_mode: "%mailer_auth_mode%"
    host:      "%mailer_host%"
    encryption: "%mailer_encryption%"
    port:      "%mailer_port%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

And parameters.yml :

parameters:
    mailer_transport: smtp
    mailer_auth_mode: login
    mailer_host: ns0.ovh.net
    mailer_encryption: null
    mailer_port: 587
    mailer_user: mymail@mydomain.fr
    mailer_password: mypass

And finally, my code sending an email (working in local) :

  $pdf->Output("billing/FA-".$value->getDateRefresh()->format('Y-m')."-".$user->getId().".pdf",'F');   
  $message = \Swift_Message::newInstance('Votre fature du '.$value->getDateRefresh()->format('m-Y'))
             ->setFrom(array("mymail@mydomain.fr" => 'Name'))
             ->setTo($user->getEmail())
             ->setBody('Voici ci joint votre relevé CONVERSEO du '.$value->getDateRefresh()->format('m-Y'), 'text/html');    
  $attachment = \Swift_Attachment::fromPath("billing/FA-".$value->getDateRefresh()->format('Y-m')."-".$user->getId().".pdf");
  $message->attach($attachment);
  $transport = \Swift_MailTransport::newInstance();
  $mailer = \Swift_Mailer::newInstance($transport);
  $this->getContainer()->get('mailer')->send($message);

Thanks you for your answers !

  • The full error message should include the information where it tried to create a directory. So see to it that you make that parent directory writable for your application ... – CBroe Jun 14 '17 at 13:18
  • I don't remember the command to see the full error message, can you tell me please ? – Gianni Fuina Jun 14 '17 at 13:23
  • Nah, sorry, looks like the warning for such a case does _not_ contain the info where it tried to create a directory ... – CBroe Jun 14 '17 at 13:24
  • Can you isolate where the problem occurs? Does it actually have to do with swiftmailer, or is it mabye rather the PDF creation that tries to create a directory to write the file to disk? – CBroe Jun 14 '17 at 13:26
  • No, the problem is swiftmailer cause my file is saved on my disk (www/billing/name-of-file.pdf). The problem comes only after **$this->getContainer()->get('mailer')->send($message);** command – Gianni Fuina Jun 14 '17 at 13:35
  • Ok, then that probably tries to create a temp dir to store the attachment data into for further processing. See if https://stackoverflow.com/questions/23405414/change-the-location-of-the-tmp-directory-for-swiftmailer-in-symfony2 helps. – CBroe Jun 14 '17 at 13:39
  • You think I have to put `$tmpDir = $this->getContainer()->getParameter('my_website.swift_tmp_dir'); \Swift_Preferences::getInstance()->setTempDir($tmpDir);` ? – Gianni Fuina Jun 14 '17 at 13:47

0 Answers0