2

I'm trying to send a very basic email in Laravel but the from field is not working. Instead of it being from the sender with their return address, it has MY return address and their name.

My .env has

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=chris@listingnaples.com
MAIL_PASSWORD=mypass;
MAIL_ENCRYPTION=tls

My controller has:

public function sendEmail(ShowingPageContactRequest $request) {

    // email me custom email
    $data = $request->all();

    Mail::send('emails.propertyemail', $data, function ($message) use ($data) {
        $message->subject('Property Query from ' . $data['name'])
            ->sender($data['email'], $data['name']) 
            ->from($data['email'], $data['name'])   
            ->to('chris@listingnaples.com')
            ->replyTo($data['email'], $data['name']);
    });
}

A dd($data) shows:

array:6 [▼
  "_token" => "ZSvuhAhkCetDFZOrQMtbDHBy2RfzECGFT03wixt3"
  "MLSNumber" => "216003681"
  "name" => "John Doe"
  "email" => "jdoe@gmail.com"
  "phone" => "(239) 555-1212"
  "comments" => "This is my comment or question."
]

So the email is there and John Doe is there. However, when I check my email it says it is from John Doe but chris@listingnaples.com!

My mail config file even has:

'from' => ['address' => null, 'name' => null],
Karl
  • 5,435
  • 11
  • 44
  • 70
Chris Farrugia
  • 1,024
  • 3
  • 17
  • 35
  • 2
    I'm going to guess this is gmail policy. You might get the desired affect by setting the Reply-To address to the form submitter's email. – Josh Rumbut May 31 '16 at 20:35
  • @JoshRumbut, that gets me close but the problem still is that it shows John Doe in the email. Hitting reply will send to his email though. – Chris Farrugia May 31 '16 at 20:43

1 Answers1

0

Adding your own Reply-To appears to be as close as it's going to get.

In Laravel 5 you can add a Reply-To using $message->replyTo ($address, $name)

See this answer and this support page, unless you added all your users manually I don't think it will work.

Other email services will let you do this, I think SendGrid does, if I recall correctly.

Community
  • 1
  • 1
Josh Rumbut
  • 2,640
  • 2
  • 32
  • 43
  • Rather than posting an answer which points to another answer, just leave it as a comment and [flag the question](http://stackoverflow.com/help/privileges/flag-posts) for moderator attention. Once you have >3000 reputation you'll be able to [vote for closure](http://stackoverflow.com/help/privileges/close-questions) as a duplicate. – miken32 May 31 '16 at 21:05
  • @miken32 this question is not quite the same as it has to do with using GMAIL through Laravel. I've added code that had to do with the comment I left on the answer. – Josh Rumbut May 31 '16 at 22:47
  • So does the dupe, which clearly explains that this is a server side issue. The framework used by the client is irrelevant. – miken32 May 31 '16 at 22:51