Reputation: 351
The following code is working fine:
Mail::send([], [], function ($message) {
$message->to('[email protected]')
->subject('Test Subject')
->setBody('<h1>Hi, welcome user!</h1>', 'text/html');
});
// check for failures
echo Mail::failures() ? 'Failed to send' : 'Sent';
However, when I added the image tag to the email's body as follows:
Mail::send([], [], function ($message) {
$message->to('[email protected]')
->subject('Test Subject')
->setBody('<h1>Hi, welcome user!</h1> <img src="http://absolute_path_to_image">', 'text/html');
});
// check for failures
echo Mail::failures() ? 'Failed to send' : 'Sent';
The snippet returns "Sent" without any error message. I checked the log files but found nothing. There was no information in the log file or whatsoever.
The application is under a sub-dommain with SSL key enabled such as https://secure.example.com.
Note that the app used to work on the same server but under a different subdomain like https://secure.olddomain.com. I'm not sure it is related to this.
If you have experienced this problem before, please help and share your solution.
Thanks, SAPNET
Upvotes: 1
Views: 381
Reputation: 5042
This one worked for me: The image is declared in the email view
<img src="{{ $message->embed(public_path() . '/x/x.png') }}" alt="" />
from Laravel doc "A $message
variable is always passed to e-mail views, and allows the inline embedding of attachments."
Hope this helps you!
Upvotes: 1
Reputation: 2525
If you send image file in mail body you need to embed
this like below
\Mail::send([], [], function ($message) {
$message->to('[email protected]')
->subject('Test Subject')
->setBody('<h1>Hi, welcome user!</h1> <img src="'. $message->embed('absolute_path_to_image') .'"> ', 'text/html');
});
Upvotes: 1