I configured my website to send mails through gmail's SMTP. My websiite is running in laravel - 4 framework. Below is the code in config>>mail.php
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'tls',
'username' => 'xxx#somedomain.com',
'password' => 'xxxxxx',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false
And this is a sample of code, on how I send mail,
$from = 'sender#somedomain.com';
$mail = Mail::send('mailer_template', ['any_data' => $data], function ($msg) use ($from, $from_name, $to_email, $subject, $attach) {
$msg->from($from,$from_name);
$msg->to($to_email);
$msg->subject($subject);
$msg->attach($attach);
});
When I send a mail, the mail is being sent. But it is sent from - 'xxx#somedomain.com'. I want it to be sent through the email in $from variabble. And the from address will change at different places. I am not sure how to configure this. Any help would be appreciated.
Have you visited this URL yet? If not, go there and follow the instructions then try to sign in again with your application on the production server.
https://accounts.google.com/displayunlockcaptcha
Try to solve it this way. Keep it mind.
Here password is not mandatory.
Keep blank for encryption field.
use smtp-relay.gmail.com.
return array(
'driver' => 'smtp',
'host' => 'smtp-relay.gmail.com',
'port' => 25, //25, 465 or 587
'from' => array('address' => 'xxx#gmail.com', 'name' => 'myname'),
'encryption' => '',
'username' => 'xxx#gmail.com',
'password' => '',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
This doesn't seems feasible as SMTP(gmail) only use one from email (whose detials are added to config/env).In your case whenever you send a mail, the mail is being sent from - 'xxx#somedomain.com'.
Related
I am creating some booking system and have HTML form in which user enter his email (and other stuff). I would like to get email as if user has send it from his email address, but my Gmail always shows that I have sent it (i.e. sender email address is same as 'username' from app/config/mail.php = XYZ#gmail.com).
This is Send::mail() method I am using
Mail::send('reservation-email', ['data' => $data], function($message) use ($data) {
$message->from($data['email'], $data['name']);
$message->to('ABC#gmail.com', 'ABC')->subject($data['subject']);
});
This is my app/config/mail.php
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'tls',
'username' => 'XYZ#gmail.com',
'password' => 'XYZ_password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I found out that I could use replyTo
Mail::send('reservation-email', ['data' => $data], function($message) use ($data) {
$message->from($data['email'], $data['name']);
$message->to('ABC#gmail.com', 'ABC')->subject($data['subject']);
$message->replyTo($data['email'], $data['name']); // <--------------------
});
but then I do not know what is the purpose of 'from' field?
Thank you in advance!
Maybe you are confuse of the purpose of 'from' and 'replyTo'.
'from' will show to your users where they received email from (It can be set in your Mail::send method in each email or in your app/config/mail.php to apply to all emails).
'replyTo' will define which address that users would send their email to when they click 'reply' button.
I'm trying to send email using Laravel. I configured mail.php with details of gmail server and used my personal gmail account credentials. It worked fine.
Then i tried to configure mail.php with the Secure SSl/TLS settings that my mail provider has provided me.
I changed host, port, username and password. I also changed encryption to ssl.
But i'm not able to send email. After some loading time, it just shows a blank page. No Error.
here's my config file(have removed doc-blocks):
<?php
return array(
'driver' => 'smtp',
'host' => 'myServerHostAddress',
'port' => portno,
'from' => array('address' => 'registration#gambiadept.com', 'name' => 'Gambia Dept'),
'encryption' => 'ssl',
'username' => 'usernameFromMyServiceProvider',
'password' => 'myPassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Probably someone can see what I'm doing wrong here. When I use ->from('test#example.com') the mail sends just fine. But when i use >from('test#hotmail.com') the mail is not sent. Everything is done in mail configuration as well.
$data = array("content" => Input::get("content"));
Mail::send("emails.text", $data, function($message)
{
$message->to('toMe#myDomain.com')
->from('test#hotmail.com' , 'Contact form message!');
});
Config:
'driver' => 'smtp',
'host' => 'mail.cornex.se',
'port' => 587,
'from' => array('address' => "christopher#cornex.se", 'name' => "Kristoffer"),
'encryption' => 'tls',
Hotmail uses Outlook SMTP. Try this:You may need to make slight modifications, but make note of the host, specifically.
'driver' => 'smtp',
'host' => 'smtp-mail.outlook.com',
'from' => array('address' => "christopher#cornex.se", 'name' => "Kristoffer")
'port' => 587, // or 25
'encryption' => 'tls',
Start working with Laravel 4.2 I tried to send email using Gmail STMP server. Below is my app/config/mail.php.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'sample_address#gmail.com', 'name' => 'Sample'),
'encryption' => 'tls',
'username' => 'sample_address#gmail.com',
'password' => 'sample password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Below is my php code.
<!-- app/views/emails/welcome.php -->
Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
$msg->from('sample_address#gmail.com', 'Laravel Admin');
$msg->to('sample_receiver#gmail.com');
});
But it does not work. I have already configured my XAMPP php.ini on my MAC OSX. It only works when sending a normal PHP mail, not SMTP. The error message that I've got from Laravel on the view page is 'Error in exception handler'. I would like to see more error information but I don't know how to get more info. What is wrong with my code? What else do I need to do or configure? Thank you!
you can put your email and name in Input
Input::merge(array('email'=>'sample_receiver#gmail.com','name'=>'sample_name'));
Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
$msg->from('sample_address#gmail.com', 'Laravel Admin');
$msg->to(Input::get('email'), Input::get('name'))->subject('You have');
});
also change 'encryption'
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'sample_address#gmail.com', 'name' => 'Sample'),
'encryption' => 'ssl',
'username' => 'sample_address#gmail.com',
'password' => 'sample password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
You should change 'encryption' for ssl and in your gmail must be enabled IMAP access in config
When you are having problems with sending mails via gmail, try this. It worked for me.
Login with your gmail account and then go to:
https://accounts.google.com/b/0/DisplayUnlockCaptcha
and click continue. Then, you have few minutes to send your mail with your code.
After this, Google will allow sign in to that account from the new source.
Hi I just uploaded a site and am getting this error with the mail service.
Connection could not be established with host smtp.gmail.com [Connection refused #111]
This are my settings in my mail.php file.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'info#thesite.com', 'name' => 'Company Name'),
'encryption' => 'tls',
'username' => '*******',
'password' => '********',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
This works perfectly locally on my system but when i upload it live, it gives me errors, please help am at the verge of delivering a project, thanks!
I also faced same problem. As for me I had changed my SMPT configuring to port 25 (with SSL) and it's was fine.
I got my solution from google, you can see at here.
Try googlemail server with ssl encryption
return array(
'driver' => 'smtp',
'host' => 'smtp.googlemail.com',
'port' => 465,
'from' => array('address' => 'info#thesite.com', 'name' => 'Company Name'),
'encryption' => 'ssl',
'username' => '*******',
'password' => '********',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Found the answer to the problem, was from my web host service providers, i use shared host so i had to call them to configure my account with them to be able to send out email, hope this helps anyone who has such problems like me in the future and this is a proper smtp configuration for gmail.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'info#thesite.com', 'name' => 'Company Name'),
'encryption' => 'ssl',
'username' => '*******',
'password' => '********',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Try changing these.
'driver' => 'mail',
'port' => 587,
'encryption' => 'ssl',
This configuration works for me in GoDaddy server.
be sure you google authentication settings are enabled:
https://www.google.com/settings/security/lesssecureapps
change driver smtp to sendmail.it worked for me
MAIL_DRIVER=sendmail