Error loading swift mailer in symfony - php

Am using swift mailer to send emails for my symfony application.But it is throwing the error:
There is no extension able to load the configuration for "transport". I am getting the error when it loads the configuration file the app is crashed. Please help me to know how can I exact define it's configuration parameters.
My app/config.yml is like:
swiftmailer:
transport: gmail
username: 'myemail#example.com'
password: 'Mypassword'
I have also checked app/Appkernel.php swiftmailer bundle is already registered:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Acme\SuperbAppBundle\AcmeSuperbAppBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
Am using the following code to send email:
$message = \Swift_Message::newInstance()
->setSubject('Hello Email') // we configure the title
->setFrom('myemail#example.com') // we configure the sender
->setTo('someone#example.com') // we configure the recipient
->setBody("Hello User");
$send = $this->get('mailer')->send($message); // then we send the message.

Your indentation is wrong. It should be like..
swiftmailer:
transport: gmail
username: 'myemail#example.com'
password: 'Mypassword'

Related

Symfony is not able to register a bundle

I have a bundle in symproject/src/MyAppBundle/src/Bundle
This folder contains MyAppBundle.php:
<?php
namespace MyCompany\Action\Provider\MyAppBundle\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MyAppBundle extends Bundle
{
}
Then I register it in App/Appkernel.php:
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new MyCompany\Action\Provider\MyAppBundle\Bundle\MyAppbundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
}
The site won't work at all after doing this. The log says:
PHP Fatal error: Uncaught Error: Class
'MyCompany\Action\Provider\MyAppProvider\Bundle\MyAppBundle' not
found in /var/www/html/symproject/app/AppKernel.php:20\nStack
trace:\n#0
/var/www/html/symproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(494):
AppKernel->registerBundles()\n#1
/var/www/html/symproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(134):
Symfony\Component\HttpKernel\Kernel->initializeBundles()\n#2
/var/www/html/symproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(197):
Symfony\Component\HttpKernel\Kernel->boot()\n#3
/var/www/html/symproject/web/app.php(19):
Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))\n#4
{main}\n thrown in /var/www/html/symproject/app/AppKernel.php on line
20
You've placed bundle class to
symproject/src/MyAppBundle/src/Bundle
folder, but namespace is
MyCompany\Action\Provider\MyAppBundle\Bundle
It should be like namespace
App\MyAppBundle\Bundle
and moved to folder
symproject/src/MyAppBundle/Bundle
Or you should change autoload section of your composer.json file to use different class loading.
https://getcomposer.org/doc/01-basic-usage.md#autoloading

Using Symfonys dump in production

I used the dump function within one of our applications and our client got used to it during development (tbh I didn't know that it won't work in prod). Now the application is going live which means no more debug mode - and no more dump function.
Is there any way to enable the dump function during prod?
Despite weird will of use dump() in production env...
If I am not mistaken dump() is from DebugBundle which is enabled only in dev and test env.
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
}
As you can see above DebugBundle is registered only in previous mentioned envs. Probably moving it out of the if will allow you to use dump() in production.
You have to indeed add this line to AppKernel.php:
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
But also change this boolean in app.php from false to true:
$kernel = new AppKernel('prod', true); // true is replacing false, in second argument here
Tested for Symfony 4.4 and works.
Read Symfony documentation 🧐, function 'dump()' is part of 'VarDumper' component, it's a dev dependency, so if you want to use it in prod you need to install it as required dependency:
❌ $ composer require --dev symfony/var-dumper
✔ $ composer require symfony/var-dumper
🚨 But I guess it's not a good practice use it in production, it could show sensitive information.

Symfony error: Class 'Symfony\Component\HttpKernel\Kernel' not found

After upgrading from Symfony 3.1 to 3.2 I get this error message :
Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not
found in /var/www/html/HeliosBlog/app/AppKernel.php on line 6
Here's what my app/autoload.php looks like:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
if (!$loader = #include __DIR__.'/../vendor/autoload.php') {
$message = <<< EOF
EOF;
if (PHP_SAPI === 'cli') {
$message = strip_tags($message);
}
die($message);
}
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
Here's what my app_dev.php file looks like:
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
And here's what my AppKernel.php looks like:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Helios\BlogBundle\HeliosBlogBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new Helios\UserBundle\HeliosUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
new FOS\ElasticaBundle\FOSElasticaBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Helios\ManagerBundle\HeliosManagerBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
//new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
new Oneup\UploaderBundle\OneupUploaderBundle(),
new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
$bundles[] = new CoreSphere\ConsoleBundle\CoreSphereConsoleBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
Already tried removing the vendor folder and doing a composer install.
Any ideas?
I was able to solve it by simply adding
require_once __DIR__.'/autoload.php';
to app/console before
require_once __DIR__ . '/AppKernel.php';`
Ran into the same error. Found that the bootstrap.php.cache was unaware of the Kernel class.
This happened due the Sensio Distibution bundle having an update.
For this I posted an issue which can be found here:
https://github.com/sensiolabs/SensioDistributionBundle/issues/302
I hope this helps others as well.
I had this issue while running composer update, because it was still using app/console (probably outdated) instead of the new bin/console.
I fixed this issue by:
removing app/console file.
creating a var/ folder in my project root directory - see this answer for explanation.
I run into this problem as well while updating my project from Symfony 2.x (can't remember whether it was 2.7 or 2.8) to 3.2. In turn out that the problem was caused by the app/console file. I believe the problem is caused by the way I created the project ages ago.
To solve this problem, I copied the app/console file from another project which I successfully upgraded to 3.2. I am not sure whether there will be some other problems down the line, but at least I got rid of this error.
The discussion that prompted me to make this change is https://github.com/symfony/symfony/issues/16713

dompdf in symfony only works in dev envirenment

I use the dompdf-bundle (slik/dompdf-bundle) in my symfony2-project (2.6.*) for the generation of pdf out of html. This works fine in my dev envirenment (MAMP) in dev (app_dev.php) and prod-mode.
In the prod envirenment I get an error with the exactly same data (DB) an code (GIT). So I checked the configuration of the server (PHP-version). Funny: When I run the prod-envirenment with app_dev.php the generation works fine!!! Where is the different between the app.php and the app_dev.php?
The error I get:
Error message in german
My AppKernel.php:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new GaertnerhuusBundle\GaertnerhuusBundle(),
new GaertnerhuusAdminBundle\GaertnerhuusAdminBundle(),
new Slik\DompdfBundle\SlikDompdfBundle()
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
I solved my issue with a work-around. I replaced the dompdf bundle with the mpdf bundle. This one works fine for my solution:
https://github.com/tasmanianfox/MpdfPortBundle

My site doesnt work in live mode

I have actually a problem with my site when i want to turn it in live mode. I have this error:
Fatal error: Class
'Lexik\Bundle\TranslationBundle\LexikTranslationBundle' not found in
/home/maisonka/www/app/AppKernel.php on line 27
but I don't understand because my bundle lexik is in my vendor and appKernel.php looks like:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Kayser\PlatformBundle\KayserPlatformBundle(),
new Liip\ImagineBundle\LiipImagineBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Lexik\Bundle\TranslationBundle\LexikTranslationBundle(),
);
I found what was my problem, I just deleted this line: "new Lexik\Bundle\TranslationBundle\LexikTranslationBundle()," and now everything works perfectly.

Categories