Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send mail in Command #10

Closed
tibo6 opened this issue Dec 19, 2017 · 8 comments
Closed

Send mail in Command #10

tibo6 opened this issue Dec 19, 2017 · 8 comments

Comments

@tibo6
Copy link
Contributor

tibo6 commented Dec 19, 2017

Hi,

I want to send an email within a Command, and it doesn't seem to work.
Don't know why.

Did I miss something ?
It works perfectly in a controller.

Thanks.

@Nightbr
Copy link
Member

Nightbr commented Dec 19, 2017

we can't help you if you don't provide code lines, errors, logs, ...

@tibo6
Copy link
Contributor Author

tibo6 commented Dec 19, 2017

I have no error.

Here's my code, nothing special:

$em = $this->getContainer()->get('doctrine')->getManager();
$contactsAmount = $em->getRepository('ContactUsBundle:Contact')->getTodaysContactsAmount();
$ordersInformation = $em->getRepository('ShopBundle:SalesOrder')->getOrdersInformation();

$currentDate = new \DateTime('now');

$message = (new \Swift_Message('[Web] Statistiques du '.$currentDate->format('d/m/Y')))
	->setFrom($this->getContainer()->getParameter('mailer_sender'))
	->setTo('xxx@xxx.com')
	->setBody($this->getContainer()->get('templating')->render('AppBundle:Emails:stats.html.twig', array(
		'contactsAmount' => $contactsAmount,
		'ordersInformation' => $ordersInformation
	)), 'text/html');

$emailsSent = $this->getContainer()->get('mailer')->send($message);

$output->writeln($emailsSent.' emails envoyés');

$emailsSent returns 0

@Nightbr
Copy link
Member

Nightbr commented Dec 19, 2017

verify the symfony env you use when you send your command, also check your spool configuration

@tibo6
Copy link
Contributor Author

tibo6 commented Dec 19, 2017

When I use this command :
php bin/console stats:send
It seems that it is launched in the dev env.
My config for dev env is :

swiftmailer:
    disable_delivery: true

And $emailsSent returns 1.

But when I use this command :
php bin/console stats:send --env=prod
And $emailsSent returns 0.
My config is:

swiftmailer:
    transport: mailjet

So no spool is configured.

@Nightbr
Copy link
Member

Nightbr commented Dec 19, 2017

put some var_dump everywhere, it can be a problem with your payload and Mailjet API reject your request that's why it failed.

@tibo6
Copy link
Contributor Author

tibo6 commented Dec 19, 2017

OK I removed a try...catch in the bundle.
And it gives me an error that I don't have when I send an email in a controller:

In CurlFactory.php line 187:
  cURL error 60: SSL certificate problem: unable to get local issuer certificate (see: http://curl.haxx.se/libcurl/c/libcurl-errors.html)

I tried to update my cacert.pem with no result.

@Nightbr Nightbr closed this as completed Dec 19, 2017
@Nightbr
Copy link
Member

Nightbr commented Dec 19, 2017

But I think we could catch runtime error (other than API error) and throw them in order to get error when there is actual error (like here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants