Bonjour,
Je cherche à envoyer un email avec le composant Email.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Routing\Annotation\Route;
class MailerController extends AbstractController
{
/**
* @Route("/email")
*/
public function sendEmail(MailerInterface $mailer)
{
$email = (new Email())
->from('tqmds10@gmail.com')
->to('stephansav@gmail.com')
->subject('Registration email')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration</p>')
;
$mailer->send($email);
}
} |
Dans le fichier .env, j'ai:
###> symfony/google-mailer ###
# Gmail SHOULD NOT be used on production, use it in development only.
GMAIL_USERNAME=tqmds10@gmail.com
GMAIL_PASSWORD=monmotdepasse
MAILER_DSN=smtp://$GMAIL_USERNAME:$GMAIL_PASSWORD@gmail
###< symfony/google-mailer ###
Lorsque je vais sur http://127.0.0.1:8000/email pour que le mail me soit effectivement envoyé, j'ai cette erreur:
Attempted to load class "Email" from namespace "App\Controller".
Did you forget a "use" statement for e.g. "Symfony\Component\Validator\Constraints\Email" or "Symfony\Component\Mime\Email"?
Pourtant, j'ai au niveau du controleur le contenu de la doc: https://symfony.com/doc/current/mailer.html
à la section "Creating and sending messages".
Pouvez vous m'aider à résoudre cela s'il vous plaît?
Partager