KiaiFighter
KiaiFighter

Reputation: 667

Laravel 5.1: Mail Driver, adding headers

I was working with Laravel 5.1 and wanted to send notifications to SMS. It was fine with @txt.bell.ca, but @msg.telus.com, it wasn't sending. Then I added a subject line, and it would send, but there was no body. Only the subject line.

Now, I found out how to fix it using PHP's mail() function.

$headers = "From: " . "[email protected]" . "\r\n";
$headers .= "Reply-To: ". "[email protected]" . "\r\n";
mail($to,$subject,$message,$headers,"[email protected]");

Now, how do I add this to the Mail::send() function from Laravel 5.1?

EDIT: For clarification, how does the parameter:

"[email protected]" 

translate to the Mail::send() closure?

EDIT2: I found the following information on the PHP docs, but it doesn't help me translate this to Laravel's function...

additional_parameters (optional)

The additional_parameters parameter can be used to pass additional flags 
as command line options to the program configured to be used when sending
mail, as defined by the sendmail_path configuration setting. For example, 
this can be used to set the envelope sender address when using sendmail 
with the -f sendmail option.

Thanks!

Upvotes: 1

Views: 847

Answers (1)

user1669496
user1669496

Reputation: 33048

Laravel doesn't include any methods to modify the headers but the underlying classes which Laravel uses to mail does support this.

The following should do the trick...

Mail::send('test', [], function(Illuminate\Mail\Message $m) {
    $m->getSwiftMessage()->getHeaders()->addTextHeader('From', '[email protected]');
    $m->getSwiftMessage()->getHeaders()->addTextHeader('Reply-To', '[email protected]');
});

Upvotes: 1

Related Questions