I'm a newbie with Symfony 3 (Symfony generally)
I want to send an email, just to test my parameters, if everything's going well, but that doesn't work.
Here my parameters.yml file:
database_host: 127.0.0.1
database_port: null
database_name: learnsymfony
database_user: root
database_password: null
mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'personalemail#gmail.com'
secret: 7759e1c20bb67e4ec0fbac5c3a4de22beed3b95d
And Here my config.yml code for swiftmailer:
transport: gmail
host: smtp.gmail.com
username: 'personalemail#gmail.com'
password: 'myPassword'
spool: { type: memory }
I found this configuration in one question here in the forum, but for my case, that was given an error "Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com [ #0]"
Any suggestion please?
I tried alot of other configurations but nothing works well...
thanks
I also faced this problem today and got resolved by following how to send email in Symfony
After following these steps don't forget to import these in your default controller:
use Symfony\Component\Routing\Annotation\Route as Route;
use Symfony\Component\HttpFoundation\Response;
And make sure your email and password which you are using "#app/config/parameters.yml" are correct.
Related
I'm attempting to send an email using SwiftMailer (version = Swift-5.4.8) after a user submits a form. I cannot determine why the email is not being sent. I have only tried using gmail setup as I've heard it is easiest to use (am new to web dev).
I have tried changing config.yml, parameters.yml
parameters.yml:
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: myemail#gmail.com
mailer_password: mypass
secret: mysecret
config.yml (relevant snippet, please lmk if need other portions)
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
DefaultController
$form = $this->createFormBuilder()
->add('from', EmailType::class)
->add('message', TextareaType::class)
->add('send',SubmitType::class)
->getForm()
;
if ($form->isSubmitted()){
$data = $form->getData();
$message = \Swift_Message::newInstance()
->setSubject('Join Our Team Request')
->setFrom($data['from'])
->setTo('myemail2#gmail.com')
->setBody(
$data['message'],'text/plain'
)
;
$this->get('mailer')->send($message);
}
return $this->render('xxx.html.twig', array("title" => "...","join_team_form" =>$form->createView()));
The view and form are rendered correctly. It appears the form submits correctly, however I never receive an email. Again new to web dev, any suggestions appreciated.
EDIT: I was able to successfully configure and send an email using the command prompt and the 'php bin\console swiftmailer:email:send' command. The issue was it was using a dev_config file, silly error. However, when I still fill out the form and click the send button, no email gets sent. Only using the above command. Any insight?
EDIT2: Solution to first EDIT was running 'composer update'.... nice...
The best practice to send mails with gmail on Symfony is described in this documentation
But for this you need to have environment variables loaded in your application, and I don't know it's your case.
The below should work. Update your config.yml to
swiftmailer:
url: 'gmail://%mailer_user%:%mailer_password%#localhost?encryption=tls&auth_mode=oauth'
spool: { type: 'memory' }
Another suggestion is to check that your form is valid before sending the mail. Otherwise the send will fail if the from is null or ""
if ($form->isSubmitted() && $form->isValid()){ ... }
Let me know if it don't work
Try to use tls encryption and smtp tranport protocol.
Your config.yml will be similar to this:
# Swiftmailer Configuration
swiftmailer:
transport: 'smtp'
host: 'smtp.gmail.com'
username: 'myemail#gmail.com'
password: 'mypass'
encryption: tls
auth_mode: login
And, you must activate access to less secure applications and disable two step authentification in your gmail account.
I'm trying to send symfony 2 a mail. I'm using google suite, I have a registered domain on aruba.it but use google mail for mail. It is a domain address, ie mail#mydomain.com. In the configuration file I have:
Auth_mode: login
Transport: "% mailer_transport%"
Encryption: "% mailer_encryption%"
Host: "% mailer_host%"
Port: "% mailer_port%"
Username: "% mailer_user%"
Password: "% mailer_password%"
Sender_address: "% mailer_sender_address%"
In the parameter file, mailer_transport: smtp mailer_host: smtp.gmail.com. But the mail is not sent. Can someone help me? How can I debug? Is there a log file?
I have tried with mailer_transport: gmail in parameters and transport: gmail in config but don't work.
I am using the following details in my parameters, it always seems to work. You might also want to read through their documentation
mailer_transport: smtp
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: youremailaddress
mailer_password: yourpassword
mailer_port: 465
I want to send confirmation email to users. I did install swiftmailer with composer and these are my configuration in parameters. yml and config.yml
parameters:
database_host: 127.0.0.1
database_port: null
database_name: xxxx
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: xxxxx#xxxxxx.com
mailer_password: xxxx
secret: ea293ee3152cb8522e591a6cb821f950cc67f499
spool:
type: file
mailer_port: 587
mailer_encryption: tls
mailer_logging: '%kernel.debug%'
config.yml
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
I added this code to my controller and I tested but nothing sent:
$message = \Swift_Message::newInstance()
->setSubject('hello')
->setFrom('example#gmail.com')
->setTo('xx.xx#xxx.tn')
->setBody('#servicom/pages/profile_commercial.html.twig', 'text/html');
# Send the message
$this->get('mailer')
->send($message);
I want to ask if the problem is from the configuration or from the code.
Thanks in advance.
See if you need some other parameters like encryption (typicaly tls) or port (generaly 587).
Documentation for adding properties there
Finally i fixed the issue by debugging first then adding the ini_set() so i share this solution :
Parameters.yml :
parameters:
database_host: 127.0.0.1
database_port: null
database_name: xxxxx
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: ssl0.ovh.net
mailer_user: xxxx#myhost.com
mailer_password: toguess
encryption: ssl
auth_mode: login
secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Add this to the function send :
ini_set('SMTP','ssl0.ovh.net');
ini_set('smtp_port',587);
And this for the Debug :
if ( $this->get('mailer')->send($message)) {
echo '[SWIFTMAILER] sent email to ' . 'malek.zarkouna#esprit.tn';
echo '' . $mailLogger->dump();
} else {
echo '[SWIFTMAILER] not sending email: ' . $mailLogger->dump();
}
i'm trying to do my first symfony project and i am using the fosuserbundle. It's working perfectly i'm just having a problem with the email confirmation, i'm not receiving anything.
This is my parameters.yml:
parameters:
database_host: 127.0.0.1
database_port: null
database_name: mydatabase
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: mymail#gmail.com
mailer_password: mypass
secret: 8c73d1f9bc7f50ce500d4a98a4627ffaa42dc905
this is myconfig.yml:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
port: "585"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: OC\UserBundle\Entity\User
service:
mailer: fos_user.mailer.twig_swift
registration:
confirmation:
enabled: true
from_email:
address: mymail#gmail.com
sender_name: myname
service:
mailer: fos_user.mailer.twig_swift
please can you help? because i searched on the web and tried but since it's my first project none of the solutions are working with me.
Try with these slight changes in your config.yml:
port: 585
auth_mod: login
The value for the port doesn't need to be enclosed in quotes. I'm not sure if this really makes a difference, but you should follow the conventions.
Since you're using smtp as mailer_transport you have also to specify the authentication mode. Check the documentation for more details:
http://symfony.com/doc/current/reference/configuration/swiftmailer.html
Eventually you'll need another value for the authentication mode.
EDIT (2016-02-19):
Instead of using smtp as mailer_transport you can use the shortcut gmail. Please see this article from the Symfony Cookbook:
http://symfony.com/doc/current/cookbook/email/gmail.html
Then you can omit the line:
auth_mod: login
This shortcut will set the host to smtp.gmail.com. In your configuration you have the host set to 127.0.0.1. This could eventually be the reason why it works with the web_profiler, but not with the real e-mail address.
$mail = \Swift_Message::newInstance()
->setSubject($message->getSubject())
->setFrom($message->getEmail())
->setBody($message->getBody());
$this->get('mailer')->send($mail);
Mails are not sent when using swiftmailer. Yet, when I go step by step in the debugger, it seems to send the email and returns sent=1. However I don't receive anything in my mailbox (gmail). I use my gmail account for sending emails, as shown below:
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: username#gmail.com
mailer_password: my-password
delivery_address: username#gmail.com
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
I've checked apache error log, nothing. I've run php app/console swiftmailer:spool:send just in case, but no luck.
What could prevent emails from being sent ?
You need either to:
1) Remove the spool line in your swiftmailer configuration, this one:
spool: { type: memory }
2) Trigger the spool queue to be sent:
php app/console swiftmailer:spool:send
But I think you are looking for option 1)
u can try this one...
Parameter.yml
mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'xxxxxxxxxxxx'
config.yml
swiftmailer:
transport: gmail
host: smtp.gmail.com
username: 'Yourmail-id#gmail.com'
password: 'Password'
The ->setTo part was missing ! That solved it.
$mail = \Swift_Message::newInstance()
->setSubject($message->getSubject())
->setFrom($message->getEmail())
->setTo("me#gmail.com")
->setBody($message->getBody());
First, when you set spool: { type: memory } it means that you actually want to send the emails manually by running the spool command: php app/console swiftmailer:spool:send. So removing that spool line is going to help.
Second, you need to properly configure your mailing host. For development purposes, I strongly recommend that you use a service such as SendGrid and configure it as detailed in this Symfony2 Mailing Setup Tutorial
The tutorial also contains details on how to properly setup a mailing service in Symfony2 and how to build mailing templates.
Third, if you want to stick with Gmail, then the correct data is:
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: your_gmail_address#gmail.com
mailer_password: 'your_gmail_password'
mailer_port: 587