I am getting error when i am sending mail in laravel - laravel

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

Related

Why giving undefined variable in sending Email attachment in Laravel?

I can't pass any variable to Email body from Controller. I have searched many solutions but no is matching with me.
I am using Mailable. But it is empty. I am not sure it is creating problem or not.
public function __construct(){}
public function build(){}
I have tested with dummy Email without passing variable. Email is sending successfully. So, I think there is no problem with configuration.
Function in controller:
public function mail()
{
$info = Invoice::find(65)->first();
// 65 is giving me value. I have checked with dd()
$data = [
'invoice' => $info->invoiceNumber
];
Mail::send(['text'=>'invoice.test'], $data, function($message) use($data){
$pdf = PDF::loadView('invoice.test');
$message->to('example#gmail.com','John Smith')->subject('Send Mail from Laravel');
$message->from('from#gmail.com','The Sender');
$message->attachData($pdf->output(), 'Invoice.pdf');
});
return 'Email was sent';
}
test.blade.php
<h1>It is working!! {{ $invoice }}</h1>
Data sending style is followed by:
Laravel Mail::send how to pass data to mail View
Try adding the $data with the PDF view:
$pdf = PDF::loadView('invoice.test', $data);
But if you want to add an email body content different with the PDF content, try this:
Mail::send([], $data, function($message) use($data){
$pdf = PDF::loadView('invoice.test', $data);
$message->to('example#gmail.com','John Smith')->subject('Send Mail from Laravel');
$message->from('from#gmail.com','The Sender');
$message->setBody('sample mail content');
$message->attachData($pdf->output(), 'Invoice.pdf');
});

Trying to send email to dynamic receiver with laravel

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

Send email from lumen

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);
});

Mail Queue processed but the Laravel don't send email

The Mail::queue method processes the service but does not send the mail.Nothing arrives in the destination email. The redis is working normally.
$data = ['nome_prefeitura'=>$gestora->pessoa->nome,'empresa'=>$n->economico->pessoa->nome,'pessoa'=>$n->pessoa->nome,'link'=>$link,'nome_secretaria'=>'Secretaria Fazenda de Dom Joaquim.'];
Mail::queue('layout_email.email_nfse', $data, function ($m) use ($n) {
$m->from('nfe#mail.com.br', 'NFS-e');
$m->to($n->email_envio, $n->pessoa->nome)->subject('Notificação de emissão de NFS-e');
});
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=redis
MAIL_DRIVER=smtp
MAIL_HOST=mail.com.br
MAIL_PORT=25
MAIL_USERNAME=nfenfe#mail.com.br
MAIL_PASSWORD=****
MAIL_ENCRYPTION=null
I changed my email server and it worked.

When i am trying to send mail from contactUS form getting this error using swiftmailer in Laravel 5.2

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']);
});

Resources