I am using vue.js as my front end and Lumen as my api service. Now I need to send emails from lumen. This is what i did for this.
.env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=********#gmail.com
MAIL_PASSWORD=**********
MAIL_FROM_ADDRESS=******#gmail.com
MAIL_FROM_NAME=Sample Email App
MAIL_ENCRYPTION=tls
and then edited the file bootstrap\app.php and uncommented the following lines.
$app->register(App\Providers\AppServiceProvider::class);
$app->withFacades();
Dotenv::load(__DIR__.'/../');
$app->withEloquent();
In the controller, I have used the following code
use Illuminate\Support\Facades\Mail;
private function sendActivationEmail( $email = null ){
$email_sent = false;
if( $email != null ){
// send email
Mail::raw('Raw string email', function($msg) {
$msg->to(['tismon#gmail.com']); $msg->from(['x#x.com']);
});
}
return $email_sent;
}
Unfortunately, this is not working. Can anyone tell me where I went wrong ?
Register MailServiceProvider in bootstrap/app.php file
$app->register(\Illuminate\Mail\MailServiceProvider::class);
$app->configure('mail');
try adding below code to AppServiceProvider.php within register function
$this->app->singleton('mailer', function ($app) {
$app->configure('services');
return $app->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer');
});
if not working After the above configuration, try Mail send function
Mail::send('user.emails.registration' , $data, function($msg) use ($to,$from,$subject)
{
$msg->to($to)->from($from)->subject($subject);
});
Related
i have a query to return all the the data in visits table
$visits = Visit::get();
i want to pass the returned data in $data so that i can send it on mail and display the data in the email body
$data = array();
Mail::send('mails.mail', $data, function ($message) use ($host_email, $to_name) {
$message->from('', '');
$message->to($host_email);
$message->subject('Visitor arrived');
});
how do i do that
You can use Laravel structure, You can create a mail class with this command:
php artisan make:mail OrderShipped
it will generate a class in App\Mail path sample named OrderShipped in build method you can call a blade view for this mail and send data to it like:
public function build()
{
return $this->view('emails.orders.shipped')
->with([
'orderName' => $this->order->name,
'orderPrice' => $this->order->price,
]);
}
and finally use this to send email to user:
Mail::to($request->user())->send(new OrderShipped($order));
look here for full documentation:
laravel mail
I was sending email to a static email and it was working but when I tried to send to a dynamic user getting data from the DB it returned this error: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required"
my sending email function:
public function send_email()
{
$getStaff=DB::table('users')
->OrderBy('id','DESC')
->first();
$staffacckey=$getStaff->access_key;
$staffemail=$getStaff->email;
$valueurl = env('APP_URL');
$info = array();
$info['url']=$valueurl;
$info['name']='tinox';
$info['msg']='test';
$info['key']=$staffacckey;
Mail::send('email.mail',$info, function($email) {
$ghost='no-reply#domain.com';
$admin='System Administrator';
$email->from($ghost, $admin);
$email->to($staffemail)->subject('email confirmation');
});
}
public function send_email()
{
$getStaff=DB::table('staff')
->OrderBy('staff_id','DESC')
->first();
$staffacckey=$getStaff->access_key;
global $staffemail;
$staffemail=$getStaff->email;
$valueOne = env('APP_URL');
$info = array();
$info['url']=$valueOne.':8080';
$info['name']='tinox';
$info['msg']='test';
$info['key']=$staffacckey;
$info['email']=$staffemail;
Mail::send('email.mail',$info,
function($email)use ($info){
$ghost='no-reply#magazinelte.com';
$admin='System Administrator';
$email->from($ghost, $admin);
$email->to($info['email'])->subject('Account activation');
});
}
just fixed the issue!! Passed variables inside the Mail function and change my env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=*******#gmail.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls
I am getting error when i am sending mail at gmail id,I am using laravel 5.7,
I am getting this errot
Call to undefined function App\Http\Controllers\send()
and my controller code is :
public function postEmail(Request $r)
{
$data=[
'user_email'=>$r->user_email,
'user_name'=>$r->user_name,
'user_phone'=>$r->user_phone,
'user_desc'=>$r->user_desc,
];
Mail:send('mail.mail', $data, function($user_desc) use($data)
{
$message->from('sumitsaoni#gmail.com', 'Send by Sumit');
$messge->to($data['sumit123#gmail.com']);
$message->subject($data['user_desc']);
});
return redirect()->back()->with('message','successfully data insertd');
}
And My Route is
Route::resource('contact', 'ContactController');
Route::post('/postEmail', 'ContactController#postEmail');
My .env file mail gmail: .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=my_email (Using my email id)
MAIL_PASSWORD=password (using my email id password)
MAIL_ENCRYPTION=tls
You should try this:
use Mail;
Mail::send('mail', $data, function($user_desc) use($data)
{
$message->from('sumitsaoni#gmail.com', 'Send by Sumit');
$message->to($data['user_email']);
$message->subject($data['user_desc']);
});
Updated answer
Mail::send('mail', $data, function($message) use($data)
{
$message->from('sumitsaoni#gmail.com', 'Send by Sumit');
$message->to($data['user_email']);
$message->subject($data['user_desc']);
});
change
Mail:send('mail.mail', $data, function($user_desc) use($data)
to
Mail::send('mail.mail', $data, function($user_desc) use($data)
try this one
Mail:send to replace Mail::send
I have a laravel 5 app and need to send a reset password link through a service sendinblue. How can I change the core functionality to use sendinblue in PasswordBroker.php?
public function emailResetLink(
CanResetPasswordContract $user,
$token,
Closure $callback = null
) {
$mailin = new Mailin(
'https://api.sendinblue.com/v2.0',
'0TYSSJBSKERNDKW'
);
$view = $this->emailView;
return $this->mailer->send(
$view,
compact('token', 'user'),
function($m) use ($user, $token, $callback)
{
$m->to($user->getEmailForPasswordReset());
if ( ! is_null($callback))
{
call_user_func($callback, $m, $user, $token);
}
});
}
Did you try to add Sendinblue as a mail driver? This github repo can help (https://github.com/agence-webup/laravel-sendinblue)
Here all your emails will be sent by Sendinblue and you will send as a regular mail in Laravel (https://laravel.com/docs/5.1/mail)
If is just for this, you can change the driver just for this kind of mail, i think that you can change the driver on runtime like this
Config::set('mail.driver', 'driver_name');
(new Illuminate\Mail\MailServiceProvider(app()))->register();
Also, you can try to listen to 'mailer.sending' event that is fired just before sending mail messages, but this is not a good approach.
when i am trying to send Mail through Contact Us Form receiving this Error
"Address in mailbox given [] does not comply with RFC 2822, 3.6.2."
I try search to find solution but I cannot find one. I edited config/mail.php
public function sendContactInfo(ContactMeRequest $request)
{
$data = $request->only('name', 'email');
$emailto="******#gmail.com";
$data['messageLines'] = explode("\n", $request->get('message'));
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});
return back()
->withSuccess("Thank you for your message. It has been sent.");
}
with configuration file
i am following this tutorial
Laravel Send Mail
use $data['email']
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto,$data['email']) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});