0

I configured my website to send mails through gmail's SMTP. My websiite is running in laravel - 4 framework. Below is the code in config>>mail.php

'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'tls',
'username' => 'xxx@somedomain.com',
'password' => 'xxxxxx',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false

And this is a sample of code, on how I send mail,

$from = 'sender@somedomain.com';

$mail = Mail::send('mailer_template', ['any_data' => $data], function ($msg) use ($from, $from_name, $to_email, $subject, $attach) {
    $msg->from($from,$from_name);
    $msg->to($to_email);
    $msg->subject($subject);
    $msg->attach($attach);
  });

When I send a mail, the mail is being sent. But it is sent from - 'xxx@somedomain.com'. I want it to be sent through the email in $from variabble. And the from address will change at different places. I am not sure how to configure this. Any help would be appreciated.

Manjunath Singh
  • 95
  • 3
  • 10

3 Answers3

1

Have you visited this URL yet? If not, go there and follow the instructions then try to sign in again with your application on the production server.

https://accounts.google.com/displayunlockcaptcha

slapyo
  • 2,979
  • 1
  • 15
  • 24
  • What does this URL has to do anything with my problem? Care to elaborate a little? – Manjunath Singh Oct 31 '14 at 18:28
  • Sure. Google "blocks" unauthorized connections from being able to send email. When you go to this URL, you will let Google know that you have an app you want to use. Then from your application try to send an email. You have to confirm that app is yours. Once you do, you'll be allowed to send the emails out. – slapyo Oct 31 '14 at 18:31
  • I did go through the URL. It still behaves the same way. I think this is something related to some laravel config, which I am confused with. – Manjunath Singh Oct 31 '14 at 18:43
  • Does the account have IMAP turned on? – slapyo Oct 31 '14 at 18:55
  • Have you tried 465 for the port and ssl for the encryption? – slapyo Oct 31 '14 at 18:56
  • Yeah, I tried it. Its still sending the mails only from the authentication account. Not from the account I want it to be sent. – Manjunath Singh Oct 31 '14 at 19:03
  • Not sure if you can send an email as being from another address. I usually set it as the reply-to address. – slapyo Oct 31 '14 at 19:11
  • Ok, then I guess its not possible. Thanks for your help! – Manjunath Singh Oct 31 '14 at 19:26
0

Try to solve it this way. Keep it mind.
Here password is not mandatory.
Keep blank for encryption field.
use smtp-relay.gmail.com.

return array(
     'driver' => 'smtp',
     'host' => 'smtp-relay.gmail.com',
     'port' => 25, //25, 465 or 587
     'from' => array('address' => 'xxx@gmail.com', 'name' => 'myname'),
     'encryption' => '',
     'username' => 'xxx@gmail.com',
     'password' => '',
     'sendmail' => '/usr/sbin/sendmail -bs',
     'pretend' => false,
  );
Koushik Samanta
  • 195
  • 1
  • 15
0

This doesn't seems feasible as SMTP(gmail) only use one from email (whose detials are added to config/env).In your case whenever you send a mail, the mail is being sent from - 'xxx@somedomain.com'.

svikramjeet
  • 1,779
  • 13
  • 27