Laravel Mail, "from" always need to be the same as "username"? - php

If I'm firing an e-mail from mysite#mysite.com.br but if I change the from to another e-mail like company#company.com.br it falls into Mail::failures()
It DOESN'T Works
// username = 'mysite#mysite.com.br'
// password = 'mypassword'
Mail::send("mail.test", [], function ($message) {
$message->to('client#client.com')
->from('company#company.com' , 'Company');
});
client#client.com falls into Mail::failures()
It Works
but if I change it to:
// username = 'mysite#mysite.com.br'
// password = 'mypassword'
Mail::send("mail.test", [], function ($message) {
$message->to('client#client.com')
->from('mysite#mysite.com.br' , 'My Site');
});

The problem was in my mail server, I talked with the support from my server and he said It its block for fraude reasons

Related

Laravel : Password reset email check against user

I have the following code to send the password reset email to the users email which is working:
$response = $this->passwords->sendResetLink($request->only('email'),function($message)
{
$message->subject('Password Reminder');
});
What i want is that user should write their username instead of email, And i will check the email against that username , And will send the email.So i came up with this idea.
$usernameToEmail = User::where('name','=', Input::get('username'))->first();
$response = $this->passwords->sendResetLink(['name' => $usernameToEmail],function($message)
{
$message->subject('Password Reminder');
});
Which is not working also.
Am i missing something ?
You're close, but your $usernameToEmail variable contains a User object, not an email string. Most likely you just need to add a method to your chain:
$usernameToEmail = User::where('name','=', Input::get('username'))->first()->email;

Laravel 4 sending mail after returning data from controller

I have a function in my controller which saves messages from users, first it saves message into database than it sends email to that user's mail address and than it returns json response to the sender.
Problem: sometimes it takes too long for email to be sent, and the sender has to wait long time for the response, or sometimes email is not even sent (due to some smpt problems etc.) and it triggers an error, however I don't really care that much if email is sent or not, most important that message is saved to the database.
What I'm trying to achieve:
I want to save message to the database, ->
immediately after that send response to the sender, ->
and only after run Mail::send();
so run Mail::send() after controller returns json to the sender, so the sender will receive a positive response regardless of how Mail::send() performs
$message = new MessageDB;
$message->listing_id = e(Input::get('listing_id'));
$message->user_id = $listing->User->id;
$message->name = e(Input::get('name'));
$message->mobile = e(Input::get('mobile'));
$message->message = e(Input::get('message'));
if ($message->save()) {
Mail::send('emails.message', ['user' => 'Jon Doe','message' => $message], function($m) use($listing){
$listing_agent = $listing->Agent;
if ($listing->agent == null) {
$mail_to = $listing->User->email;
$name = '';
}else{
$mail_to = $listing->Agent->email;
$name = $listing->Agent->first_name.' '.$listing->Agent->second_name;
}
$m->to($mail_to)->subject('new message from company.com');
});
return ['success' => 1, 'message' => 'messasge has been sent'];
You can use Mail Queueing functions of Laravel. Here's the Link
Mail::queue('emails.welcome', $data, function($message) {});Queue mail for background Sending.
Mail::later(5, 'emails.welcome', $data, function($message){});Define Seconds after which mail will be sent.

How to check email sent or not in laravel 5

I have a function to send a email for registered users. This is how i am checking if an email should be sent or not.
$email=$details->email;
$subject = 'Looking for blood donor';
$status=Mail::send('emails.welcome', $data, function($message)
use($subject,$email){
$message->from('no-reply#bloodlink.com', 'Blood Link');
$message->bcc('no-reply#bloodlink.com');
$message->to($email)->subject($subject);
});
I am using if for check email sent or not but it not work..
if($status)
{
return Response::json(array('status'=>'success',
'data'=>("Your email has been sent successfully")
), 200);
}else{
return Response::json(array('status'=>'error',
'data'=>("something went wrong..!!")
), 200);
}
The Mail::send() method doesn't return anything.
You can use the Mail::failures() (introduced in 4.1 I think) method to get an array of failed recipients, in your code it would look something like this.
Mail::send('emails.users.reset', compact('user', 'code'), function($m) use ($user)
{
$m->to($user->email)->subject('Activate Your Account');
});
if(count(Mail::failures()) > 0){
$errors = 'Failed to send password reset email, please try again.';
}
Have a look into failure method, here

laravel 5 send email with html elements and attachment using ajax

I am stuck on the point where i want to send an email using ajax. Find code below.
$user = \Auth::user();
Mail::send('emails.reminder', ['user' => $user], function ($message) use ($user) {
$message->from('xyz#gmail.com', 'From');
$message->to($request['to'], $name = null);
// $message->cc($address, $name = null);
// $message->bcc($address, $name = null);
$message->replyTo('xyz#gmail.com', 'Sender');
$message->subject($request['subject']);
// $message->priority($level);
if(isset($request['attachment'])){
$message->attach($request['attachment'], $options = []);
}
// Attach a file from a raw $data string...
$message->attachData($request['message'], $name = 'Dummy name', $options = []);
// Get the underlying SwiftMailer message instance...
$message->getSwiftMessage();
});
return \Response::json(['response' => 200]);
Now i want to send this email using ajax and upon request complete i want to display message on same page that your message sent successfully.
i found the solution for this, but this is to send plain message directly using Mail::raw() function which is working perfectly. But i am not able to attach files here or some html codes.
Any suggestion in this regard.

Laravel Not sending Email

am having some sort of an issue with sending mails from my website with Laravel 4, I followed the on-line documentation but haven't successfully sent a mail with Laravel my code is as show below.
Mail::send('emails.contactmail', $data, function($message)
{
$name = Input::get('name');
$email = Input::get('email');
$message->from($email, $name);
$message->to('info#mysite.org', 'Info at My Site')
->subject('Website contact form');
});
I use following code for sending temporary password in case of forgot password
public function postForgotPassword(ForgotPasswordRequest $request){
$email=$request->email;
$objUser=DB::table('users')
->where('email','=',$email)
->select('email','id','first_name','last_name','user_group_id')
->first();
$string = str_random(15);
$pass=\Hash::make($string);
$objUser2=User::find($objUser->id);
$CURRENT_TIMESTAMP=new DateTime();
$objUser2->temporary_pass=$pass;
$objUser2->pass_status=1;
$objUser2->updated_at=$CURRENT_TIMESTAMP;
$objUser2->save();
$data=array("email"=>$email,"pass"=>$string,"first_name"=>$objUser->first_name,"last_name"=>$objUser->last_name);
$email=array("email"=>$email);
Mail::send('emails.forgot_password',$data, function($message) use($email) {
$message->to($email['email'],'MyProject')->subject('Password Recovery ');
});
return Redirect::to('auth/login')->with('flash_message','Check your email account for temporary password');
}
And I write email template in forgot_password.blade.php which is located in view.emails folder.

Categories