smartrahat smartrahat - 5 months ago 42
PHP Question

How to change header information of mail in Laravel?

I am creating a simple contact us form using Laravel 5.1

public function sendMessage(){
$data = [
'name' => Input::get('name'),
'email' => Input::get('email'),
'subject' => Input::get('subject'),
'body' => Input::get('body')
Mail::send('',$data, function($message) use($data){
$message->from($data['email'], $data['name']);
Session::flash('success_message','Mail sent successfully!');
return redirect('contact');

Everything is working fine but the sender email address is not the one it get from the contact page. The email is sent from the address which I configure in

I want to have the email from the sender email address which he filled up contact form. Or, you can say I want to change the header information (only
, I can change other information).


Well Laravel will send the mail through the given smtp server. I guess the smtp server (e.g. google doing this) will not let you change your from address to another address then the account belongs to.

If you want to reply to this address directly in your email programm you can add $message->replyTo($data['email'], $data['name']);.