0

So i'm trying to send a mail from a form using laravel, the email gets sent to the right address i specify, but the problem is, it ignores my message->from('$request->sender_email','Sender name') and always uses my gmail address as the sender I have echoed the sender_email and it exists. It also sends the correct Sender Name too

Heres my controller method

public function insert_sendmail(Request $request)
{
   $this->validate($request,
    [

      'sender_email' => 'required',
      'receiver_email' => 'required',
      'receiver_name' => 'required',
      'message' => 'required'

    ]);
    $data = array('name'=>"$request->message");
    // dd($request);

   Mail::send(['text'=>'mail'], $data, function($message) use($request)
   {

      $message->to($request->receiver_email, $request->receiver_name)->subject('Basic Email Notification Testing Mail');
      $message->from("$request->sender_email",'Admin');
   });
  return redirect()->route('settings.index')->with('info', 'Email Sent');

}

Please help me spot anything i'm doing wrong

Willower
  • 1,099
  • 8
  • 22
  • You're sending the email using your gmail account? – StyleSh1t Mar 24 '18 at 18:51
  • @StyleSh1t I used my gmail account in my .env file – Willower Mar 24 '18 at 18:54
  • @MattGibson lemme check it out – Willower Mar 24 '18 at 18:54
  • Try this $message->from($request->sender_email,'Admin'); The value of $request->sender_email should match the value of your gmail account – mohit Mar 25 '18 at 08:16
  • @mohit i know this. but i want the sender's email from to be dynamic. Meaning it uses the sender's email address that's been registered on my database as where the email is being sent from. – Willower Mar 25 '18 at 15:22
  • @MattGibson they did not actually answer the question there. Can you suggest any other method i can use to achieve what i want? – Willower Mar 25 '18 at 15:26
  • For that you will have to change the SMTP details i think you can't do that with Gmail sMTP – mohit Mar 25 '18 at 17:40
  • @mohit yes you cant do that with gmail. I'm currently setting up mailgun for that. I'd let you know if it works out – Willower Mar 25 '18 at 19:27
  • For anyone who runs into this issue, switch over to mailgun. They have lesser restrictions as compared to using gmail to setup your smtp. – Willower Mar 27 '18 at 08:28

0 Answers0