How send mail in laravel and RollbarNotifier - php

I develop a laravel app and I want to automatically send emails with remainder to users.
I created command like in this article. But I get this error:
[Illuminate\Contracts\Container\BindingResolutionException]
Unresolvable dependency resolving [Parameter #0 [ <required> $config ]] in
class RollbarNotifier
This is my code:
.env
MAIL_DRIVER=smtp
MAIL_HOST=example.com
MAIL_PORT=465
MAIL_USERNAME=noreply#example.com
MAIL_PASSWORD=PAssWord
MAIL_ENCRYPTION=SSL
MAIL_FROM_ADDRESS=noreply#example.com
MAIL_FROM_NAME="FROM FROM"
ROLLBAR_TOKEN=<my_token>
config/mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'example.com'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'noreply#example.com'),
'name' => env('MAIL_FROM_NAME', 'FROM FROM'),
],
'encryption' => env('MAIL_ENCRYPTION', 'SSL'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];

It looks like your dependency injection is not working. It is missing a configuration file.
I am not sure which package you are using. But when I look at the installation manual at https://github.com/jenssegers/laravel-rollbar I see you also have to add some configuration in the services.php:
'rollbar' => [
'access_token' => env('ROLLBAR_TOKEN'),
'level' => env('ROLLBAR_LEVEL'),
],

Related

Unable to resolve NULL driver for [Illuminate\Mail\TransportManager] Laravel 6

I'm trying to send an email using a Laravel Mail, following everything on the documentation, below is my mail.php
'default' => env('MAIL_MAILER', 'smtp'),
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
and tried just using the php mail by setting up on .env mail part to NULL
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=myemail#domain.com
MAIL_FROM_NAME="${APP_NAME}"
and tried to send
Mail::to('drako#domain.com')
->bcc( app('config')->get('mail')['bcc'])
->send(new Get_a_quote($data));
if(count(Mail::failures()) > 0){
return false;
}else{
return true;
}
but my attempt returns an error
Unable to resolve NULL driver for [Illuminate\Mail\TransportManager].
any help, ideas is greatly appreciated.
You need to replace the MAIL_DRIVER with MAIL_MAILER in your .env file.

What's the correct configuration to send emails using Sendmail in Laravel?

I am using Laravel 7 and I want to send an email using the Sendemail driver via Laravel Mail facade. It worked when I used the PHP mail function but I want to use the Laravel Mail facade instead.
My .env file email configuration:
MAIL_DRIVER=sendmail
MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'
My default mail setup in config/mail.php:
'default' => env('MAIL_MAILER', 'sendmail'),
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
],
'ses' => [
'transport' => 'ses',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
I have created Mail class as explained in the docs. What is the right configuration to make it work?
First, change the default MAIL_MAILER to use Sendmail.
MAIL_MAILER=sendmail
Then in config/mail.php, update the Sendmail line.
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs')
],
Finally, if you need to change the MAIL_SENDMAIL value then add this line to your .env.
MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'

I am getting this error while implementing Mail in Laravel 5.5---->Missing argument 1 for Illuminate\Support\Manager::createDriver()

Error - Missing argument 1 for Illuminate\Support\Manager::createDriver()
My env file-
MAIL_DRIVER=smtp
MAIL_HOST=smtp.****.com
MAIL_PORT=587
MAIL_USERNAME=info#*****.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
All the keys in mail.php of config folder are correct.
My controller function looks like this
function send(Request $request)
{
$this->validate($request,[
'name'=>'required',
'email'=>'required|email',
'subject'=>'required',
'message'=>'min:10'
]);
$data=array(
'name'=>$request->name,
'email'=>$request->email,
'subject'=>$request->subject,
'bodyMessage'=>$request->message
);
Mail::send('mail.admin',$data,function($message) use ($data)
{
$message->from($data['email']);
$message->to($data['info#****.com']);
$message->subject($data['subject']);
});
}
What mistake am i making here?
Here is my mail.php file
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.****.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs', 'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
I replaced all the settings and codes with my own codes and the email was sent correctly. I suggest removing the composer.lock file and remove the vendor directory and run the composer install again. Maybe the complete package is not installed.

Too few arguments to function Illuminate\Support\Manager::createDriver(), 0 passed in framework/src/Illuminate/Support/Manager.php

I am using smtp protocol to send mails using mailtrap. It is working perfectly in localhost but it is giving error.
Symfony\Component\Debug\Exception\FatalThrowableError Type error: Too
few arguments to function Illuminate\Support\Manager::createDriver(),
0 passed in
public_html/vendor/laravel/framework/src/Illuminate/Support/Manager.php
on line 88 and exactly 1 expected
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=name
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=null
mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.org'),
'port' => env('MAIL_PORT', 2525,
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
First: Make Sure that you have mail.php and services.php in config folder set
with the following respectively:
mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.org'),
'port' => env('MAIL_PORT', 2525,
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
And services.php (note that this includes the mailgun configuration)
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'sparkpost' => [
'secret' => env('SPARKPOST_SECRET'),
],
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
];
ADD THIS ON YOUR boostrap/app/php file
$app->configure('mail'); // this is to configure the mail
$app->configure('services'); // and to configure the services
//$con = env('MAIL_DRIVER');
// dd($con);
dd(config('mail')); // this is to print the mail configuration so you can know what mail configuration are being read.
return $app;
run php artisan serve within the terminal
just to see the contents of the mail configuration.
PLEASE NOTE
I Noticed that the simple fix is to just UPDATE/MODIFY THE .env file with the credentials(using gmail smtp server as example)
MAIL_DRIVER_=smtp (instead of MAIL_DRIVER, update it the mail.php)
MAIL_HOST_=smtp.gmail.com (instead of MAIL_HOST)
MAIL_PORT_=587
MAIL_USERNAME=youremail#domain.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
MAILGUN_DOMAIN=
MAILGUN_SECRET=
After that, if you were already running your server. Kill it and rerun it again. This should solve your errors,
REASON
For reasons I couldn't explain, some of the mail config parameter didn't reflect until I applied the change above.
Secondly I later changed the .env settings to the original name eliminating the extra "_" as well as updated the mail.php, and had to kill the already running server and rerun it again before it reflected and ran well or worked!.
Hope this helps

How to achieve password reset functionality in laravel 5.4

I implemented laravel 5.4 auth login. My other functionality is in working like login, logout etc. But for password reset functionality I am receiving following error. I am confused where I am wrong.
Swift_TransportException in StreamBuffer.php line 268: Connection
could not be established with host smtp.thenaturalgolfcourse.com
[php_network_getaddresses: getaddrinfo failed: Name or service not
known #0]
Below is my .env file detail is reqired for mail setting.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mysite.com
MAIL_PORT=465
MAIL_USERNAME=support#mysite.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
same details I used in mail.php like below
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mysite.com'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'support#mysite.com'),
'name' => env('MAIL_FROM_NAME', 'The My Site'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME','support#mysite.com'),
'password' => env('MAIL_PASSWORD','mypassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Please give me solution or tell me where I am wrong..

Categories