How to check whether email is successfully sent or rejected? - laravel

I am using this function in laravel to send a mail.
Mail::send('blah', $data, function($message) {
// content
});
I want to check whether the email successfully sent or rejected.
I tried mail:failures() but it always show successfully sent.

Related

Laravel 5.7 verification email has wrong url when sending email through event

I'm trying to use laravel's 5.7 email verification to send an email when an account is registered. I have an event that fires that send the url when a user is registered. The event dispatch can be seen here.
protected function registered(Request $request, $user)
{
UserRegistered::dispatch($user);
}
The event fires and a listener sends an email by using the following code.
public function handle(UserRegistered $event)
{
$event->user->notify(new VerifyEmail);
}
This then does send the email verification mail to my email address so the event is working. However the issue I'm having is the verification email link that is contained in the email is incorrect.
http://localhost/email/verify/19?expires=1544182945&signature=b4337e1c7e07a7e7117a8696a30b456ab2a304cdea563ca7aea6c90bb9a2541f
Here is what is being sent by email. However the app url should not be localhost and instead by core-site.test. e.g. http://core-site.test/email/verify etc...
Does anyone know why the url is incorrect and how I can fix it?

Laravel 5.3 Upgrade Forgot Password Email Never Sent

Trying to figure out why ForgotPassword is not sending an email after upgrading to 5.3. I've traced it through PasswordBroker, User, CanResetPassword, and finally to RoutesNotifications::notify where it dips into the Service Container, and apparently sends the email instance on line 21 app(Dispatcher::class)->send([$this], $instance);, but no email is sent... any ideas?
I'm using the MailGun driver, and using the old mail API all the ported code is still working just reset password using the new notifications API is not.
I stuck a stub in ResetPassword::toMail, but it never invokes this method:
public function toMail()
{
Log::info('toMail');
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url('password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}
Okay, I found out why it doesn't invoke ResetPassword::toMail the RoutesNotifications::routeNotificationFor mail key returns $this->email, and we're using $this->username.
Reading the docs again after flipping through the code paid off since I recognized a bit more in the docs that I had already seen and now the heading caught my eye a bit more so just look at this to quickly solve this issue Customizing The Recipient

MailGun Laravel - Cant send to gmail

I have mailgun setup and working with my custom domain name, as in, I can send test emails to me#mydomain.com but when I try to send to gmail I get the following error.
ClientException in RequestException.php line 107:
Client error: `POST https://api.mailgun.net/v3/mydomain.com/messages.mime` resulted in a `400 BAD REQUEST` response:
{
"message": "Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the act (truncated...)
My mailgun account is setup to work with my domain name correctly and my custom email address doesn't match my site domain name and mail gets delivered to it from mailgun no problems...
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mydomain.com
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster#mydomain.com
MAIL_PASSWORD=ljhasdlkfhklahsdfklhklasdhflkhasdlkfhkhasdkflh
MAILGUN_SECRET=key-asdflkhjaklsdfkljaslkdfjlkjasdfkj
MAIL_FROM=postmaster#mydomain.com
MAIL_ENCRYPTION=tls
Its weird that when trying to send to a gmail address it gives tells me I need to activate my mailgun account but when sending to a custom domain name address its works perfectly, anyone have any ideas.. Here is the function I am using to send the emails
Mail::send('emails.recontact', ['title' => $title, 'content' => $content], function ($message) use ($request){
$message->from( 'me#mysite.ie', $request->input('name') );
$message->to('myname#gmail.com');
$message->subject("Website Enquiry");
});
You may need to activate you account.
Please login to your mailgun account and make sure there is no a yellow message on the top of the screen that said:
"Please activate your account to start sending emails. We sent an activation email to {your_email}. Resend activation. Update email address."
This solved my problem :)
I am working on mailgun but i faced different problem when recipient reply mail stores instead of delivered

Laravel 5 google mail smtp issue

I am using laravel 5 for sending mail using google smtp. in my env file i set
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME={user}
MAIL_PASSWORD={pass}
and in my route
get('sendemail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.welcome', $data, function ($message) {
$message->from('alam.ifta#gmail.com', 'Learning Laravel');
$message->to('ifta123#gmail.com','Bappa')->subject('Learning Laravel test email');
});
return "Your email has been sent successfully";
});
it send email successfully, but in my inbox i see that the sender is not alam.ifta#gmail.com but from that account which i use in .env file. Where is the problem. Thank you.
Gmail does not let modify the address your emails come from. It's intended for personal use, not a server's outgoing mail.
If you want that, you need to use an email service designed for sending such emails. Laravel supports many of them out-of-the-box like Mailgun, Mandrill, and Amazon SES. Each has a generous free tier.

Saving Mandrill webhook to database

Im having trouble understanding how to process the data sent to my post route from the mandrill webhook.
I have set up my route and registered it in the mandrill settings. Sending a test from the dashboard works fine (webhook is triggered on send, open, and hard_bounce):
Route::post('/mailApi/webhooks', 'ContactController#postMandrill');
Currently, I'm just trying to ensure that I can receive the webhook and make sure that I understand the format.
I have created a function for in my ContactController for testing purposes:
public function postMandrill(){
$data = Input::get("mandrill_events");
$mandrill = new Mandrillemail;
$mandrill->event = $data;
$mandrill->msg_subject = 'test';
$mandrill->save();
}
When I send an email to trigger the webhook, I get no errors and nothing is saved in the database. It seems like the route isn't touched at all. What do I need to do to access the webhook?

Resources