I have problem,
when I send mail from localhost everything works fine,
but when send from server I don't receive mail and I don't get error.
My env. file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxx#gmail.com
MAIL_PASSWORD=xxxx
and function
protected function contactMe() {
Mail::send('request2e', array(
'subject' =>Input::get("subject"),
'email' => Input::get("email"),
'message1' => Input::get("message1"),
'number' => Input::get("number")
), function ($message) {
$message->from('xxxx#gmail.com', 'Contact');
$message->to('yyyy#gmail.com')->subject('Contact');
});
return redirect('/');
}
Have any idea what could be the problem?
If you're using Gmail smtp you have to use the smtp driver:
MAIL_DRIVER=smtp
MAIL_PORT=587
MAIL_ENCRYPTION=tls
Make sure to clear the config cache if you have to (required in production).
php artisan config:cache
Everything else seems to be aok.
In your Gmail settings page do the following:
Click on the Forwarding/IMAP tab and scroll down to the IMAP Access section: IMAP must be enabled in order for emails to be properly copied to your sent folder.
I think you there is a problem with google app security functionality.
From above given link, turn on this functionality and check for this issue.
Hope this helps you.!
Related
I want to translate password reset emails into Laravel. (for frontend I use Vue.js)
in config/app.php I have set the desired language
'locale' => 'sl',
'fallback_locale' => 'sl',
than I downloaded translations from https://github.com/Laravel-Lang/lang and put folder "locales\sl" in downloaded repository into resources\lang\sl in my project.
I use custom email notification app\Notifications\ResetPasswordNotification.php where I added:
use Illuminate\Support\Facades\Lang;
and for translating I used:
->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
This translation is stored in resources\lang\sl\sl.json
Now when the email is sent I get no errors but the email is still in English, but let's say API responses are in the desired language.
{"status": "We have emailed your password reset link!"}
^^ this status gets translated into the language specified in config/app.php
I run these two lines, but no effect...
php artisan config:clear
php artisan cache:clear
I managed to solve this.
I moved sl.json form resources\lang\sl\sl.json into resources\lang\sl.json :)
After I changed my shared host, I have problem with Forgot password link. In my app all sections need to send email work fine but when I pressed forgot password button I got success alert that link sent to your email but when I checked my mails it was empty!!(app doesn't send link)
I checked all my logs in app and host there weren't any error.
I use default Laravel settings.(Laravel 7).
In .env file add new variable called MAIL_FROM_ADDRESS=your_smtp_from_mail_id . you have to set MAIL_FROM_ADDRESS to valid SMTP from_mail email id. sometimes in the .env file, this variable doesn't exist. if it is not set manually; when sending mail it is picking up a default mail id which is hello#example.com. please have look here config/mail.php
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
i think this should work !
This worked for me.
Need help setting up Mail on my Laravel application.
My .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=*****#*****.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
This returns the following error :
Expected response code 250 but got code "", with message ""
I had the same problem and it turns out Office 365 doesn't let you use a different from setting in your mail sending function than the one you use in your .env file.
I wanted to set the from name and email address according to whatever data was coming in via the request of a form submission as to capture them in the CRM system and it threw that same exception. Not sure if this helps you, but this was how I solved my problem.
Here's my code in the controller as an example:
$data = [
'name' => $request->get('name'),
'surname' => $request->get('surname'),
'email' => $request->get('email'),
'phone' => $request->get('phone'),
'subject' => $request->get('message-subject')
];
$from = $data['name'] . ' ' . $data['surname'];
Mail::send('mail.mymail', compact('data'), function($message) use ($request, $data, $from) {
$message->to('example#companyiworkfor.com', 'Some Company I Work For')->subject('Website Contact Form');
$message->from($data['email'], $from);
// Office 365 won't let you use a different from address here,so use same email as per your .env
});
We were getting the same error message in one of our customer's internal tool, which runs on Symfony 3 and Swiftmailer v5.4.4.
After some debugging, I found out that there was a previous exception thrown by Swiftmailer. The reason was the response from smtp.office365.com:
421 4.7.66 TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit https://aka.ms/smtp_auth_tls. [AM6PR02CA0020.eurprd02.prod.outlook.com]
Microsoft dropped support for TLS 1.0 und 1.1. After some research I found this github issue:
This commit (4c4b333) introduced TLS 1.1 / 1.2 support, but didn't make it to any release yet. Unfortunately all Swiftmailer users (besides the ones using recent dev-master) are tied to TLS 1.0, which starts to give issues
In one of the comments #fabpot replied that they've backported the bugfix to Swiftmailer 5. It landed in release 5.4.10.
After upgrading Swiftmailer, the mailing worked again.
I have quite a few emails that must go to the administrator of the site, which is the email declared in the .env
So, in each mailable that I create, for the $this->to(), I want to add the email defined in the .env so that in case it changes, I dont have to go around each mail and manually change it.
So I tried this just for testing purposes:
Route::get('send', function(){
Mail::send(new AdminEmail());
})->name('test.email');
The Mailable looks like this in the constructor:
public function __construct()
{
$this->from('no-replya#gmail.com', 'Tester');
$this->to(env("MAIL_USERNAME"), 'Admin');
}
In the .env I have the configurations:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=admin#gmail.com
MAIL_PASSWORD=z6c4czc44
MAIL_ENCRYPTION=tls
When I try to send the email I see the following error:
Address in mailbox given [] does not comply with RFC 2822, 3.6.2.
So it seems like am not managing to access the variable correctly.
How can I access the email from the .env file?
Instead of env("MAIL_USERNAME") try config('mail.username')
It first tries to get config variable value in the .env file and if it couldn't find the variable value in the .env file it will get variable value from config/mail.php
Using 5.0
in config/session.php I have set 'domain' => '.example.com' but it is not working. I cannot persist a session on even one domain like this.
My site has many subdomains:
vancouver.example.com
newyork.example.com
etc... they are hosted on the same server and are the same Laravel app (share the same storage directory)
I login with the correct credentials, upon which the app redirects to another page on the site, and I have no session at that point. var_dump(Auth::user()) shows null even though I logged in with the correct credentials.
storage/framework/sessions shows 14 different files there, they are all for me and I cleared them out before I started testing this.
I'll attach my AuthController#postLogin method below, which works fine if session.php 'domain' => null
public function postLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email', 'password' => 'required',
]);
$credentials = $request->only('email', 'password');
if ($this->auth->attempt($credentials, $request->has('remember'))) {
Session::flash('message', 'You are now logged in.');
Session::flash('status', 'success');
if (str_contains($_SERVER['HTTP_REFERER'], '?goto=')) {
$params = explode('?', $_SERVER['HTTP_REFERER'])[1];
$target = explode('=', $params)[1];
} else {
$target = '/';
}
return redirect($target);
}
return redirect($this->loginPath())
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => $this->getFailedLoginMessage(),
]);
}
Figured it out. Update domain => '.example.com' in session.php and clear the cookies for the site in question.
#gadss
you need to add session table like this
php artisan session:table
composer dump-autoload
php artisan migrate
and change .env to
SESSION_DRIVER=database
also modify config/session.php
'driver' => env('SESSION_DRIVER', 'database') and
'domain' => '.yourdomain.com'
after that clear your browser's cache and cookies.
You'll need to update the session configuration to persist the session in domain-wide including subdomains. Follow the steps given below.
Go to config/session.php and update the domain with prefix . as config => '.your-domain.com'.
Then clear your application cache, Open the Chrome DevTool and Go to Application > Application > Clear Storage. You'll need to clear out the previous cookies also.
run artisan command php artisan config:cache or php artisan config:clear to drop previously cached laravel application configs.
If you are using database as the session driver, You need to create a session table for that. run command php artisan session:table to generate the session table migration and then migrate it using php artisan migrate. Then perform the three steps given above.
With Laravel 8 it becomes more simplier :
Add SESSION_DOMAIN to your .env file :
SESSION_DOMAIN=.yourdomain.tld
Clear configuration cache :
php artisan config:cache
Delete your browser sessions cookies, then session become shared between all your subdomains.
In my case I used to AutoLogin user to subdomain once account is created on www. domain. Worked fine.
Have you tried storing the sessions in the database, memcached, or redis instead of in files? I had a similar situation to yours and storing sessions in the database solved the issue for me.
For some reason Laravel's session driver doesn't handle cross domain sessions correctly when using the file driver.
If someone still gets the problem with subdomain cookie. Try to change Session Cookie Name in config/session.php
If someone needs to sync session in subdomains with different laravel application sharing same database
Follow all the instructions of #Kiran Maniya
Then you have to keep same application name in order to get same session name. Or just change the cookie config in config/session.php
You can hardcode it if keeping same name is not possible.
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
)
to something like:
'cookie' => env(
'SESSION_COOKIE',
'session_sharing_application_session'
)