i have all ok..working in the localhost..the mail is sending from localhost...but when i uploaded it in to the server mail is not coming and no exception is thrown too...here is my .env file code
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmail#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
and here is my controller code
protected function create(array $data)
{
//dd($data);
$models = new User;
$user=User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
/*'usertype' =>$data['usertype'],*/
'status' => 0,
]);
$use = array('name' => 'Admin');
//$models->emailw = Auth::user()->email;
$message_id = "";
$name = "";
Mail::send('emailMessage', $use, function ($m) use ($message_id,$name){
$message_id = DB::getPdo()->lastInsertId();
$name = DB::table('users')->select('name')->where('id','=', $message_id)->pluck('name');
//$email = DB::table('users')->select('email')->where('id','=', $message_id)->pluck('email');
$subject = "Id = ". $message_id . " name = " .$name[0];
$m->to('mrbbangladesh2017#gmail.com')
->subject($subject);
});
return $user;
}
and here is my mail.php code
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => [
'address' => 'admin#mrbglobalbd.com',
'name' => 'Admin',
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
];
what i need to change here?
There can be many things which can go wrong in your condition. I try to list all possible options:
Try port 465 instead of 587 as Gmail normally uses that one.
Check if port is blocked on your live server.
Login to your gmail account( mygmail#gmail.com ). Go to https://myaccount.google.com/security , Scroll down till bottom of page. In right you will see: Allow less secure apps, make sure that option is on.
I hope it helps
Related
I have a database table for all the values that is needed for an smtp, I want to call it and change the values on the mail.php but can't I can dd(config('mail')) fine but it still gives me an error for some reason
The error
Expected response code 250 but got code "550", with message "550 5.7.1 Relaying denied "
Inside my ServiceProvider
// get email view data in provider class
View::composer('*', function ($view) {
// Get the slug from parameters
$slug = $this->app->request->route('slug');
if(isset($slug)){
$configuration = ContactConfig::where("slug", $slug)->first();
if (!is_null($configuration)) {
$config = array(
'driver' => $configuration->driver,
'host' => $configuration->host,
'port' => $configuration->port,
'username' => $configuration->user_name,
'password' => $configuration->password,
'encryption' => $configuration->encryption,
'from' => array('address' => $configuration->sender_email, 'name' => $configuration->sender_name),
);
Config::set('mail', $config);
return;
}
};
if(isset(Auth::user()->id)) {
$configuration = ContactConfig::where("user_id", Auth::user()->id)->first();
if(!is_null($configuration)) {
$config = array(
'driver' => $configuration->driver,
'host' => $configuration->host,
'port' => $configuration->port,
'username' => $configuration->user_name,
'password' => $configuration->password,
'encryption' => $configuration->encryption,
'from' => array('address' => $configuration->sender_email, 'name' => $configuration->sender_name),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
\Config::set('mail', $config);
}
}
});
I followed 2 questions that give the same answers but for some reason it doesn't not work for me, I removed the configurations on my .env file but it's stated that it should'nt be needed and I wanted to test if the dynamic settings works.
The approach that I went with is directly changing the config in my Livewire Component I just put the Config::set() function inside the sendEmail() function before using the function Mail::to()
Hello I try send email from my registration script to user (link). I have config file:
config/mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 's44.linuxpl.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'verify#coins.webmg.pl'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('verify#coins.webmg.pl'),
'password' => env('MySecretPassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'stream' => [
'tls' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]
];
And file .env:
MAIL_DRIVER=smtp
MAIL_HOST=s44.linuxpl.com
MAIL_PORT=587
MAIL_USERNAME=verify#coins.webmg.pl
MAIL_PASSWORD=MySecretPassword
MAIL_ENCRYPTION=tls
Script to send mail from RegisterController.php
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$verifyUser = VerifyUser::create([
'user_id' => $user->id,
'token' => str_random(40)
]);
$sendMail = Mail::to($user->email)->send(new VerifyMail($user));
return $user;
}
Class VerifyMail
class VerifyMail extends Mailable
{
use Queueable, SerializesModels;
public $user;
public function __construct($user)
{
$this->user = $user;
}
public function build()
{
return $this->view('emails.verifyUser');
}
}
And file to send verifyUser.blade.php
<h2>Welcome to the site {{$user['name']}}</h2>
I don't know what is wrong in this configuration, because I can log in correctly to the mailbox, so the email address and password are correct. Additionally, laravel does not return any errors, the script itself is executed correctly.
Restore your mail.php file to its defaults:
Replace:
'username' => env('verify#coins.webmg.pl'),
'password' => env('MySecretPassword'),
with
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
You misunderstood how the env($key, $default = null) method works. The first argument it takes is the key of the environment variable (eg. 'MAIL_USERNAME'), and the second argument is the default value (which can be optional).
Store your mail credentials in the .env file only, and never within your config files' env() calls.
Laravel Docs: Configuration
I found solution. The problem is with file .env. The file was loaded with previous settings. It was enough to clean the cache files.
php artisan config:cache
php artisan config:clear
php artisan cache:clear
Here it is well described Trying to get Laravel 5 email to work
just restore your config/mail.php to default one and try to set the below values in your laravel .env file directly
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc#gmail.com
MAIL_PASSWORD=abc#123
May wish this will help you Thanks
I'm getting the following error trying to send mail from localhost using smtp:
Expected response code 250 but got code "503", with message "503 5.5.4
Error: send AUTH command first. "
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.com
MAIL_PORT=465
MAIL_USERNAME=robot#domain.com
MAIL_PASSWORD=11111111
MAIL_ENCRYPTION=ssl
MAIL_FROM=robot#domain.com
MAIL_NAME=MY.NAME
config/mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.yandex.com'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => 'robot#domain.com',
'name' => 'MY.NAME',
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('robot#domain.com'),
'password' => env('11111111'),
'sendmail' => '/usr/sbin/sendmail -bs',
];
Tried: changing ports, encryption, clearing cache, restarting server in all possible combinations. :)
As I see it there's one more parameter I need to pass to the mailer library. Some thing like
auth_mode=login_first
Can this be done through laravel settings?
I'm posting my working settings. You've got to check how laravel env helper function is used in your config file. Also when using smtp.yandex.com auth email and form email must match.
Laravel Docs for env()
The env function gets the value of an environment variable or returns a default value:
$env = env('APP_ENV');
// Return a default value if the variable doesn't exist...
$env = env('APP_ENV', 'production');
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.com
MAIL_PORT=465
MAIL_USERNAME=robot#mydomain.com
MAIL_PASSWORD=123123123
MAIL_ENCRYPTION=ssl
MAIL_FROM=robot#mydomain.com
MAIL_NAME=MY.NAME
config/mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.yandex.com'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM','robot#mydomain.com'),
'name' => env('MAIL_NAME','MY.NAME'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME','robot#mydomain.com'),
'password' => env('MAIL_PASSWORD','123123123'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
Controller function
public function testmail()
{
$user = Auth::user();
$pathToLogo = config('app.url').'/images/logo/logo_250.png';
Mail::send('emails.testmail', array('user' => $user, 'pathToLogo' => $pathToLogo), function($message) use ($user)
{
$message->to($user->email);
$message->subject('Test message');
});
return redirect()->route('home')->with('message','Test message sent.');
}
I am trying Laravel do a mail send. When I execute the code, nothing happens, no errors, no logs, no returning mails, anything.
Config Env
MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.es
MAIL_PORT=587
MAIL_USERNAME=noreply#domain.es
MAIL_PASSWORD=xxxxxx
MAIL_FROM=noreply#domain.es
MAIL_NAME=Domain Name
MAIL_ENCRYPTION=null
Mail.php
return [
'driver' => 'smtp',
'host' => env('MAIL_HOST', 'mail.domain.es'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'noreply#domain.es', 'name' => 'Domain Name'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', 'noreply#domain.es'),
'password' => env('MAIL_PASSWORD', 'xxxxx'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => env('MAIL_PRETEND', true),
];
Code in the controller
$accion = Accion::findOrFail($id);
Mail::send('emails.notificar', ['accion' => $accion], function ($m) use ($accion) {
$m->from(env('MAIL_FROM'), env('MAIL_NAME'));
$m->to("jtd#adagal.es", "Jtd")->subject('Nova acción formativa');
});
Did you see any error? I did everything that is marked in the official docs but still no response, no mail, no error.
pretend' => env('MAIL_PRETEND', true) change this to false
When the mailer is in pretend mode, messages will be written to your application's log files instead of being sent to the recipient.
I want to send email from my localhost in laravel 5 using driver: smtp and host: smtp.gmail.com
here is my sample code for sending email after successful account open.
public function postRegister(Request $request)
{
$password = PropertyHelper::randomPassword();
$arrUser = [
'_token' => $request->input('_token'),
'name' => $request->input('name'),
'mobile' => $request->input('mobile'),
'email' => $request->input('email'),
'password' => $password,
'password_confirmation' => $password
];
$validator = $this->registrar->validator($arrUser);
if ($validator->fails())
{
$this->throwValidationException(
$request, $validator
);
}
$data = [
'name' => $request->input('name'),
'password' => $password,
'email' => $request->input('email'),
];
$this->auth->login($this->registrar->create($arrUser));
$data = [
'name' => $request->input('name'),
'password' => $password,
];
$emailSend = Mail::send('emails.signup', $data, function($message){
$message->to(Auth::user()->email)
->subject('নতুন একাউন্ট');
});
dd($emailSend); //output 1
if($emailSend)
{
return redirect($this->redirectPath());
}
}
Here is my config/mail.php file
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => 'hizbul25#gmail.com', 'name' => 'Admin'],
'encryption' => 'tls',
'username' => 'myEmail#gmail.com',
'password' => 'gmailPassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
This code did not show any error but not also send email. If i try to print the out of email send it says 1. Any idea please ??
try to change the mail info inside .inv under root folder instead of mail.php as previous versions of laravel