Sending html content as mail body laravel mail sending application - laravel

My controller is
public function basic_email() {
$data = array('name'=>"Virat Gandhi",'roll'=>"123");
Mail::send(['text'=>'mail'], $data, function($message) {
$message->to('xyz#gmail.com', 'Basil Baby')->subject
('Laravel Basic Testing Mail');
$message->from('abc#yahoo.com','Virat Gandhi');
});
echo "Basic Email Sent. Check your inbox.";
}
My blade is
Hi, {{ $name }}
your roll number is {{$roll}}
please click on the link to verify your account
Mail is being received. but the mail body is displaying html content as such. How to make verify you account a html link in mail body

Change your key text to html in your send function.
text key send data as a plain text
Mail::send( ['html' => 'mail']...
Also change {{}} to {!! !!}
Reference:
Laravel -> Mail

If you are trying to verify registered users, I would suggest you to use Laravel's build-in verification system.
You can follow the link:
Laravel email verification

Related

Laravel get email sent success message

This question seems too simple to be asked here I think but I'm new to Laravel and I could not find a way to get any success feedback when an email has successfully been sent.
I had some successes with getting an error messages by doing this:
#if($errors->any())
<p class="feedback-error">{{ $errors->all()[0] }}</p>
#endif
PS: I want to get the message for when an email has been sent to reset their password.
If you are working with a third party SMTP client then you should make a Listener to its Webhooks.
Example if you are using third party they will accept the content you gave them. They will queue it in their side. I'm using POSTMARK, when the mail bounced my application will listen for Webhook request that will send email notification or discord notification on my side that the email was bounced.
But if you are sending mail via Laravel you should do this.
try {
Mail::to([EMAIL OF THE CLINET])->send(new SendNotifMail());
return back()->with(['message' => 'email was successfully sent']);
} catch (Exception $e) {
return back()->withErrors(['invalid email address']);
}
EDIT:
You can see apply this in front end like:
#if (Session::has('message'))
{{ Session::get('message') }}
#endif
To get the response message for when the reset password email has been sent, there is a variable 'status' which can be listened to within the html like:
#if( Session::has('status') )
<p class="feedback-success">{{ Session::get('status') }}</p>
#endif

How can I forward an email in laravel?

I am using https://github.com/Webklex/laravel-imap to retrieve email from my mail server.
Now I need to forward the exact mail with all body(text, html, attachments). How can I forward the email?
I was working on the same thing, and wanted to give a more concrete answer related to using Laravel-IMAP to get emails and then forward them.
See this answer which helped out a lot.
use Illuminate\Mail\Mailable;
public function build()
{
$this->view('emails.emails.received')->with('body', $this->message->getHTMLBody())
->from($this->message->getFrom()->first()->mail, $this->message->getFrom()->first()->personal)
->to('<forwarded_email>')
->replyTo($this->message->getReplyTo()->first()->mail, $this->message->getReplyTo()->first()->personal)
->subject($this->message->getSubject());
foreach ($this->message->getAttachments() as $attachment) {
$this->attach($attachment);
}
$this->withSwiftMessage(function ($msg) {
$msg->getHeaders()->addTextHeader('In-Reply-To', $this->message->getMessageId());
$msg->getHeaders()->addTextHeader('references', $this->message->getReferences());
});
return $this;
}
Also - My template emails.emails.received contains only the following:
{!! $body !!}
Sure, that's possible, I recommend you to use:
Laravel Mail Auto Embed
Its use is very simple, you write your markdown normally:
<!-- eg: resources/vendor/mail/markdown/order-shipped.blade.php -->
#component('mail::message')
# Order Shipped
Your order has been shipped!
#component('mail::button', ['url' => $url])
View Order
#endcomponent
Purchased product:
![product](https://domain .com/products/product-1.png)
Thanks,<br>
{{ config('app.name') }}
#endcomponent
And when you send the email, it replace the url image for inline data, most simple to handle and to forward an email
When sending, it will replace the link that would normally be generated:
<img src="https://example.com/products/product-1.png">
by an embedded inline attachment of the image:
<img src="cid:3991f143cf1a86257f8671883736613c#Swift.generated">
I will give you the idea
first you need to take this email data which you have taken from laravel-imap and store in a variable
first you need to specify the wanted message lets say you are looking for a message that contains specific information which can be specified
like this
foreach($aFolder as $oFolder){
//Get all messages by custom search criteria
/** #var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->where(["CUSTOM_Word" => "Hello"]])->get();
}
now you have a specific email with all of its components
now send it to the desired email or list of emails (use foreach)
pass $aMessage variable to your send function then
$receiver_email = 'john#gmail.com';
$data = array ('subject' => '$aMessage->getSubject().'<br />'' ,
'Attachments' => '$aMessage->getAttachments()->count().'<br />'',
'body' => '$aMessage->getHTMLBody(true)';
)
Mail::send('emails.message', $data, function ($message) {
$message->to($receiver_email)
->subject($aMessage->getSubject());
$message->from('youremail#app.com' , 'your name')
});
and in your emails/message don't forget to put your custom message with subject , attachments and body as an output
in emails/message it will be the message which will be sent to the client and you can design it using html , css just like any other file it uses the laravel blade template here is an example from Medium
Hello <strong>{{ $subject}}</strong>
<p>{{$body}}</p>
Note : you might find some typos or errors because like what i have told you i gave you the idea but can't give you exactly what you want.
and here you can find another question about sending emails you might want to take a look at it
Mail::send( ['html' => 'emails.newinvoice'], ['text' => $emailtext],
// ^^^^
Also replace auto-escaped block {{ }} with unescaped {!! !!} in the template:
<p> {!! $text !!} </p>

Laravel 5 - Sending notification via Mail shows HTML source instead of HTML

I'm sending a user - registered confirmation link email after signup.
When i open that mail with my desktop client, all shows very well. When i open that mail with my Android phone client called "Mail" (version 10) it shows the HTML tags and every line of HTML source code instead of rendered HTML.
What am i doing wrong? This is the toMail method from the notification:
public function toMail() {
$subject = trans('mail.registration_confirmation');
return (new MailMessage)
->subject($subject)
->greeting($this->registeredUser->greeting())
->line(trans('app.thank_you_for_registering', ['app' => settings('app_name')]))
->line(trans('app.confirm_email_on_link_below'))
->action(trans('app.confirm_email'), route('register.confirm-email', $this->token))
->line(trans('app.confirm_email_call_to_action'))
->line("Just another line");
}

Laravel 5.1/5.6 How to send a url in email blade

I am using Mail::send function to send emails to my end users with dynamically generated links in them Below is my sample code for the function -
$myemail = "some email adderess";
$myurl = "some url that will be emailed";
Mail::send('emails.mybladetemplate', ['myemail' => $myemail] , function ($message) use ($myemail){
$message->subject('Your favorite links');
$message->from('someone#company.com', 'Company');
$message->to($myemail);
});
I am having trouble passing $myurl to the blade template and publishing it. I even used HTML{{ }} in my blade template but no success. I have tested Mail::send with other templates and it works fine. Just not when I pass the variables.
Added ['myemail' => $myemail, 'myurl' => $myurl] and use ($myemail, $myurl) to solve for it.

Sending html email with in-line image attachment causes outlook to block the message (potentially unsafe attachment)

I am trying to send a HTML email in Laravel 5.2 using Amazon SES like this:
Mail::send('emails.test', [
'header_logo' => public_path('assets/images/default_email_header.jpg'),
'html_email' => 'hello world! Email <b>html test</b>'
], function($message) {
$message
->to('latheesan#domain.com', 'Latheesan K')
->subject('Test ses email');
});
And my mail view blade emails/test.blade.php file contains this line:
<img src="<?php echo $message->embed($header_logo); ?>" style="margin: 0; padding: 0;">
<br>
{!! $html_email !!}
When this email is sent; it ends up in junk folder with this message:
Outlook blocked access to the following potentially unsafe attachment: default_email_header.jpg
Any idea why this happens? if i move the message back into inbox, the email looks right. But why is it unsafe? why is it always ending up in junk folder?
Ok this is not issue with the image or your SES application. This is happening due to your outlook security acting up which might be set up by your office IT.
Here is some trouble shooting.
https://www.itsupportguides.com/office-2013/outlook-2013-how-to-unblock-potentially-unsafe-attachments/
Here is another support doc from Microsoft.
https://support.microsoft.com/en-us/kb/829982

Resources