Laravel 5 google mail smtp issue - laravel

I am using laravel 5 for sending mail using google smtp. in my env file i set
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME={user}
MAIL_PASSWORD={pass}
and in my route
get('sendemail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.welcome', $data, function ($message) {
$message->from('alam.ifta#gmail.com', 'Learning Laravel');
$message->to('ifta123#gmail.com','Bappa')->subject('Learning Laravel test email');
});
return "Your email has been sent successfully";
});
it send email successfully, but in my inbox i see that the sender is not alam.ifta#gmail.com but from that account which i use in .env file. Where is the problem. Thank you.

Gmail does not let modify the address your emails come from. It's intended for personal use, not a server's outgoing mail.
If you want that, you need to use an email service designed for sending such emails. Laravel supports many of them out-of-the-box like Mailgun, Mandrill, and Amazon SES. Each has a generous free tier.

Related

From and to address in same in gmail

I am sending mail with laravel. Mail is in gmail but from and to address is same in gmail why ? i am confused.
env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc2020
MAIL_PASSWORD=Abc#123
MAIL_ENCRYPTION=tls
\Mail::send('invoice', array(
'name' => $user_details->name,
'email' => $user_details->email,
'subject' =>'Order is placed',
), function($message) use ($req){
$message->from($req->email,'Order');
$message->to('abc2020#gmail.com')->subject('Order is Placed');
});
Invoic is send in email but from address is same as to address
from:abc2020#gmail.com
to:abc2020#gmail.com
What is changes in code so that from address is from $req->email..
Google rewrites the From and Reply-To headers in messages you send via its SMTP service to values that relate to your Gmail account. So changing it in the codebase will make no difference.
If you need to modify the From and/or Reply-To addresses, you need to consider alternative SMTP services.

connecting gmail to a laravel application: send and receive emails from withing the app

I'm trying to connect gmail to a laravel application so I can send and receive emails from withing the app just like this image: https://ibb.co/1QkDTTh.
I just don't have any idea how to start, so if any of you have a general idea on how this could be done please tell me. thanks.
try this
add the following code in .env file and then go to gmail security(https://myaccount.google.com/security) and then turn on less secure apps
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=your gmail Id
MAIL_PASSWORD=your gmail password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=info#example.com
MAIL_FROM_NAME=test
As far as I know you should allow less secure app to use your google account.
This can be done in your google account
Then you have to add your parameters to your config/mail.php file or in the .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_GMAIL_USERNAME
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl
now you can add your php code to send emails using your google account
use Illuminate\Support\Facades\Mail;
//...
$to_name = 'TO_NAME';
$to_email = 'TO_EMAIL_ADDRESS';
$data = array('name'=>"Sam Jose", "body" => "Test mail");
Mail::send('emails.mail', $data, function($message) use ($to_name, $to_email) {
$message->to($to_email, $to_name)
->from('FROM_EMAIL_ADDRESS','Artisans Web')
->subject('Artisans Web Testing Mail');
;
});
your view should be resources/views/emails/mail.blade.php
Hi <strong>{{ $name }}</strong>,
<p>{{ $body }}</p>
That's it

How to set up mailgun with laravel 5.7?

I am trying to set up mail sending with mailgun on my deployed laravel application. I am able to send email verification emails, but I can't send to my email. For example:
Notification::route('mail', 'admin#mywebsite.org')
->notify(new Feedback($user->email, $subject, $message));
When I was using mailtrap.io to test my mail sending it worked perfectly.
My .env file looks like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAILGUN_SECRET=key-<key>
MAIL_USERNAME=postmaster#sandbox<somenums>.mailgun.org
MAIL_PASSWORD=<mypass>
MAIL_ENCRYPTION=tls
When I try to send the email it brings this error: Expected response code 250 but got code "554", with message "554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings. "
welcome to SO.
Please have a deeper look at the Laravel official documentation where you can find everything you need to set up the mailgun driver.
Mailgun Driver
To use the Mailgun driver, first install Guzzle, then set the driver option in your config/mail.php configuration file to mailgun. Next, verify that your config/services.php configuration file contains the following options:
'mailgun' => [
'domain' => 'your-mailgun-domain',
'secret' => 'your-mailgun-key',
],
After updating your conf you have to change the MAIL_DRIVER env variable from smtp to mailgun. All the other settings for username, password and so on are not required.

Namecheap\Mailgun - receiving email

I am wondering how to setup namcheap and maligun to receive emails. Currently I am able to send emails with my laravel application through maligun, but I am not sure how to setup maligun to receives replies?
I have seen the options of setting up routes to receive emails to some wanted enpoint, but currently I am not receiving anything on maligun, so I have nothing to forward. I am getting the message:
This is the mail system at host eforward3e.registrar-servers.com.
I'm sorry to have to inform you that your message could not be
delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can delete your
own text from the attached returned message.
The mail system
: unknown user:
"support#my-domain.com"
Final-Recipient: rfc822; support#my-domain.com
Original-Recipient: rfc822;support#my-domain.com Action: failed
Status: 5.1.1 Diagnostic-Code: X-Postfix; unknown user:
"support#my-domain.com"
How should I set this up?
Hope you register your domain at mailgun, if not then do it here. Once your domain register follow below steps:
1) Get domain and API Key from Mailgun > Doamins > Domain Information page
2) Setup config/services.php:
'mailgun' => array(
'domain' => 'YOURDOMAINNAME',//Place your register domain name here...
'secret' => 'API Key',//Place your API Key here...
),
3) Setup .env:
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=YOURPASSWORD
MAIL_ENCRYPTION=tls
4) Check with sending mail from laravel application.
That's it...

MailGun Laravel - Cant send to gmail

I have mailgun setup and working with my custom domain name, as in, I can send test emails to me#mydomain.com but when I try to send to gmail I get the following error.
ClientException in RequestException.php line 107:
Client error: `POST https://api.mailgun.net/v3/mydomain.com/messages.mime` resulted in a `400 BAD REQUEST` response:
{
"message": "Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the act (truncated...)
My mailgun account is setup to work with my domain name correctly and my custom email address doesn't match my site domain name and mail gets delivered to it from mailgun no problems...
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mydomain.com
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster#mydomain.com
MAIL_PASSWORD=ljhasdlkfhklahsdfklhklasdhflkhasdlkfhkhasdkflh
MAILGUN_SECRET=key-asdflkhjaklsdfkljaslkdfjlkjasdfkj
MAIL_FROM=postmaster#mydomain.com
MAIL_ENCRYPTION=tls
Its weird that when trying to send to a gmail address it gives tells me I need to activate my mailgun account but when sending to a custom domain name address its works perfectly, anyone have any ideas.. Here is the function I am using to send the emails
Mail::send('emails.recontact', ['title' => $title, 'content' => $content], function ($message) use ($request){
$message->from( 'me#mysite.ie', $request->input('name') );
$message->to('myname#gmail.com');
$message->subject("Website Enquiry");
});
You may need to activate you account.
Please login to your mailgun account and make sure there is no a yellow message on the top of the screen that said:
"Please activate your account to start sending emails. We sent an activation email to {your_email}. Resend activation. Update email address."
This solved my problem :)
I am working on mailgun but i faced different problem when recipient reply mail stores instead of delivered

Resources