Laravel get email sent success message - laravel

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

Related

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>

Sending html content as mail body laravel mail sending application

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

Redirect with success or error message without using sessions

How can i redirect with success or error message without using sessions in laravel
Currently I am using the following code for redirect :
return redirect('dashboard')->with('status', 'Profile updated!');
But this code Need session to display the success message.
You can set another variable status type along with the status like below,
return redirect('dashboard')->with(['status'=>'Profile updated!','status_type'=>'success']);
And in your dashboard blade file use
#if(isset($status))
<p class="alert alert-{{ $status_type }}" >{{ $status }}</p>
#endif

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

Laravel 4 Login Credentials mismatch does not send back error data

Everything is fine, Login, Validation, and Username/Password combination mismatch, except for the mismatch, it does not send back the data that I'm sending.
This is my code, and I've tried different login techniques, and same issue.
This is my blade page errors section:
<div id="formErrorDiv">
#if ($errors->has())
<h2>* Please check your errors.</h2>
#endif
#if (isset($mismatch))
<h2>* {{ $mismatch }}</h2>
#endif
</div>
while the $errors-has() for the fields' validation works perfectly, the $mismatch variable always turns out empty.
This is my controller login section:
if($auth){
return Redirect::intended('/');
} else {
//dd('auth else');
$mismatch = 'Login Credentials Error.';
return Redirect::route('account-sign-in')
->with('mismatch', $mismatch);
}
although when I use the dd('auth else') it does work, and so it enters the else section but always sends nothing with the redirection.
You need to use Session::get() to retrieve the value you pass with with():
#if(Session::has('mismatch'))
<h2>* {{ Session::get('mismatch') }}</h2>
#endif
errors is the exception here. Because it's very common to pass that to the next view, Laravel built it in so the errors variable from the session is automatically available in your views...

Resources