I use Swift Mailer in Symfony 2, It appears in the profile bar that the email has been sent but it seems it was not.
Controller :
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('koorahome#gmail.com')
->setTo('hzweb4#gmail.com')
->setBody(
$this->renderView(
// app/Resources/views/Emails/registration.html.twig
'verify/email.html.twig', array()
), 'text/html'
)
;
$this->get('mailer')->send($message);
Paramaters :
mailer_transport: smtp
mailer_encryption: ssl
mailer_host: smtp.gmail.com
mailer_user: koorahome#gmail.com
mailer_password: *******
It seems your setting need set as your server problem. I mean you need to set sender same as your server.
For example, your server http://example.com than you need to create mail in your server as: name#example.com see your config in your server mail and set it in your SwiftMailer.
If your server is localhost and want to test email, use mailtrap : https://mailtrap.io/. Register, create mail test, see config for symfony and setup.
Check your Gmail settings. You may have to allow SMTP emails.
Try below:
Log into your Gmail or Google Apps email Settings and click on the Forwarding/IMAP tab. Scroll down to the IMAP Access section. IMAP must be enabled in order for emails to be properly copied to your sent folder.
Related
I'am experiencing the issue of receiving the transport username (email) as the sender instead of the email written in the from() function when sending emails using Symfony Mailer.
Here is the code:
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailSmtpTransport;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
$transport = new GmailSmtpTransport($username, $password);
$mailer = new Mailer($transport);
$email = (new Email())
->from(new Address($data["email"]))
->to("dest#gmail.com")
->subject(sprintf("Apply for a %s.", ucfirst($data["subject"])))
->html($template);
$mailer->send($email);
Any idea how to fix it?
To fix this issue, I found the following solutions:
Use a different SMTP server that does not override the From header. You can try using a different email service provider or configuring your own SMTP server to avoid this issue.
Set the Sender header in your email message. This header specifies the email address that should be used as the actual sender of the message, while the From header specifies the name and email address of the person or entity sending the message. You can set the Sender header using the sender() method of the Symfony\Component\Mime\Email class.
For example:
use Symfony\Component\Mime\Email;
$email = (new Email())
->from(new Address($data["email"]))
->to('dest#gmail.com')
->subject(sprintf("Apply for a %s.", ucfirst($data["subject"])))
->html($template)
->sender(new Address($data["email"]));
Configure your SMTP server to allow sending emails with a different From address. This may require modifying the configuration of your email service provider or SMTP server to allow sending emails with a different From address. You can consult the documentation of your email service provider or SMTP server for more information on how to do this.
Note that some SMTP servers may still override the From header even if you set the Sender header or configure the server to allow sending emails with a different From address. In such cases, you may need to use a different SMTP server that does not override the From header.
I have to run mail function on laravel with google smtp.gmail.com or default mail() DRIVER only cant use other methods as client requirement but both not working. I tried everything that I can
I tried smtp.gmail.com and default mail() DRIVER both but no result
.env file code
With smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxxx#gmail.com
MAIL_PASSWORD=xxxxxxxx
MAIL_ENCRYPTION=tls
With mail
MAIL_DRIVER=mail
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Controller code
$template_data = EmailTemplate::getEmailTemplateByID($template->id);
$email_params['verification_code'] = $user->verification_code;
$email_params['name'] = Helper::getUserName($user->id);
$email_params['email'] = $user->email;
Mail::to($user->email)
->send(
new GeneralEmailMailable(
'verification_code',
$template_data,
$email_params
)
);
It's not showing any error just showing success message that you are registered or we send recovery email but no email in inbox
you need to add mail host and mailport as these are requires to send mail.
just go through this link must resolve this issue
https://appdividend.com/2018/03/05/send-email-in-laravel-tutorial/
I'm trying to send an email to swiftmailer with symfony 2.8.
Before 2 months I was able to send emails without problems.
But since one week, I'm not able to send an email.
I tried all these solutions but the issue persists:
- allow less secure app Gmail
- change port from 465 to 587
- trying both mailer_transport SMTP and Gmail
but nothing works.
Any help, please?
Error :
Connection could not be established with host smtp.gmail.com [ #0]
500 Internal Server Error - Swift_TransportException
code :
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('mohamed.maddouri#esprit.tn')
->setTo('mohamed.maddouri#esprit.tn')
->setBody("test mail")
;
$this->get('mailer')->send($message);
I face a problem I don't understand.
I use SwiftMailer to send emails (ex : registration confirmation) from a website using the Mailjet SMTP. Mails are not sent.
The Symfony profiler says that 1 mail is spooled when I create a user account, but it is never sent.
php bin/console swiftmailer:spool:send returns 0 emails sent. I tried memory and file spools.
When using the php bin/console swiftmailer:email :send, mails are correctly sent (mails have the mailjet headers and they are in the mailjet sent mails interface).
When I'm trying the OVH SMTP, mails are correcly sent both from the application and cli command, so the problem seems to be a SwiftMailer misconfiguration.
Here is my setup :
app/config/config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host_prod%"
port: "%mailer_port_prod%"
encryption:"%mailer_encryption_prod%"
username: "%mailer_user_prod%"
password: "%mailer_password_prod%"
spool: { type: memory }
app/config/parameters.yml
mailer_transport: smtp
mailer_host_prod: in-v3.mailjet.com
mailer_port_prod: 587
mailer_encryption_prod: tls
mailer_user_prod: api_key
mailer_password_prod: api_secret
mailer_host_ovh: ssl0.ovh.net
mailer_port_ovh: 465
mailer_encryption_ovh: ssl
mailer_user_ovh: email
mailer_password_ovh: password
It works for me. I had the same issue, but I had an exit after sending the email and in this case, the spool doesn't send the email, because the kernel does not end properly. If you remove spool: { type: memory }, then it will send the email.
To send the email properly with spool, then you need to end the kernel properly.
Did your request finish without any errors when creating the message ?
On https://symfony.com/doc/current/email/spool.html : "This means the email only gets sent if the whole request got executed without any unhandled exception or any errors."
Finally, it was the sender's email who was wrong. I forgot to update it after going prod.
At this moment, Mailjet successfuly receive the email but put it in queue and don't send it. On Symfony side, it is a success.
I have moved an application to amazon builded in symfony2 and using swiftmailer for sending emails, I am not able to send emails from the application.
So searching around the solution for sending emails. Please let me know if any solutions for sending email SES or configuring SMTP for symfony2.
I got mine to work with the following details:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
auth_mode: login
encryption: tls
port: 587
logging: "%kernel.debug%"
And lastly, make sure the send FROM email address is verified.
I never played with AWS SES but you can use mailjet to send email. You just need to configure Swiftmailer Transport to use their SMTP and you're done.
They also ensure that your email are well sending (ie: not in spam) by providing several technique. You will have to setup some of them.
They do not provide example for Swiftmailer, but here a good one for Zend (you will see how easy it is):
$config = array(
'ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'username' => 'your_Mailjet_API_Key',
'password' => 'your_Mailjet_Secret_Key');
$transport = new Zend_Mail_Transport_Smtp('in-v3.mailjet.com', $config);
$mail = new Zend_Mail();
$mail->setFrom('your_sender#address.com', 'You');
$mail->addTo('recipient#example.com', 'Anybody');
$mail->setSubject('My first email by Mailjet');
$mail->setBodyText('Hello from Mailjet & Zend Framework !');
$mail->send($transport);
Amazon SES has an excellent Php API from the official AWS Php SDK:
http://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-ses.html
As you can see, SES is not used as a SMTP gateway (like Mailjet does) but as a HTTP API (via Guzzle, a Php library for HTTP queries). It's always an important decision to rely or not on Amazon services such as S3/SeS/SNS etc... maybe you don't want to depend on no Amazon technology?
You can try to use AWS SES Monitor Bundle to manage the sending of emails through SwiftMailer with Symfony.
The problem is that when you start with AWS SES you are in the sandbox and to go live you need to file an issue to Amazon to ask to put you out of the sendbox.
The requirement is that you can manage bounces and complaints.
To get notifications about those, you need to connect to Simple Notification Service (the other option is to get notifications via e-mail).
To automate all this stuff, you can use AWS SES Monitor Bundle that do all of this for you.
It also registers a plugin for SwiftMailer that can intercept messages and avoids the sending of messages to address to which you should not send e-mails.