I'm trying to test some emails within a laravel 4.2 app and have configured mail.php to use mailtrap
here's my mail.php config:
return array(
'driver' => 'smtp',
'host' => 'smtp.mailtrap.io',
'port' => 2525,
'from' => array('address' => 'website#domain.co.uk', 'name'=>'Domain'),
'encryption' => 'null',
'username' => '12345XX',
'password' => '12345XX',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I'm trying to use this within a development environment with a vagrant box (homestead)
I'm using a basic test script as follows to send a test email:
$data = array(
'activationCode' => '123456789',
'id' => 27,
'user' => [
'id'=>27,
'first_name'=>'TEST USER',
'last_name'=>'LAST NAME',
'email'=>'test#domain.org.uk'
]
);
$firstResult = Mail::send('emails.auth.accessPending', $data, function ($message) {
$message
->to('email#domain.com')
->subject('website registration');
});
I get a NULL response and nothing appears in the mailtrap inbox.
What am I missing in either my configuration or script to get the app to send test emails?
Thanks
Can you check if you have .env file those
MAIL_HOST=mailtrap.io
_PORT=2525
MAIL_USERNAME=your username
MAIL_PASSWORD=your pass
MAIL_ENCRYPTION=null
Ok - it was working - sort of. The reason there was no output because the mail config file for local development was set to pretend
Revealed by a quick check of the log file
Ta
Related
I want to override the default mail settings in config/mail.php or .env which Laravel uses by default. I'm setting up the dynamic configs (coming from DB) but email when sent is still going from the "from" address set in the config/mail.php or .env.
Any suggestion for the above words??
Here's the part of the code I'm using:
$mailConfigs = [
'driver' => 'smtp',
'port' => $dbSettings->smtp_port,
'host' => $dbSettings->smtp_host,
'encryption' => $dbSettings->smtp_encryption,
'username' => $dbSettings->smtp_email,
'password' => $dbSettings->smtp_password,
'sendmail' => '/usr/sbin/sendmail -bs',
'from' => [
'address' => $dbSettings->smtp_email,
'name' => 'XXXXX'
],
];
Config::set('mail', $mailConfigs);
// print_r(Config::get('mail'));
// Config here are reflected correctly if printed but when email is sent, it again uses the "from" address which is setup in .env and totally ignores the one setup above.
$res = Mail::send([], $data, function ($message) use($mailConfigs)
{
// email body, etc...
});
I am working in Laravel and have added the mail configuration in the "MailConfigServiceProvider" but it's giving error.
I am currently using Laravel 7.0.
Is there anything missing in the configuration or I have taken a wrong approach?
Here is the error
Error
InvalidArgumentException
Unsupported mail transport [1].
Here is my mail service provider code:
public function boot()
{
$emailServices = EmailServices::where(['active' => 1])->latest()->first();
if ($emailServices) {
$config = array(
'driver' => $emailServices->driver,
'host' => $emailServices->host,
'port' => $emailServices->port,
'username' => $emailServices->username,
'password' => $emailServices->password,
'encryption' => null,
'from' => array('address' => 'codingdriver15#gmail.com', 'name' => $emailServices->name),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Config::set('mail', $config);
}
}
I have also added the provider in the config/add.php file
'providers' => [
App\Providers\MailConfigServiceProvider::class,
],
I am known to the .env file approach but here I am trying to make it dynamic.
Any help or suggestion will be helpful and appreciated.
MAIL_DRIVER: SMTP
MAIL_ENCRYPTION: TLS
PORT:2525
I'm trying to send email via cakephp3.
This is my app email config:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
],
],
And this is controller :
public function index() {
$this->autoRender = false;
$email = new Email('default');
if (
$email->from(['mymail#gmail.com' => 'My Site'])
->to('mymail#gmail.com')
->subject('About')
->send('My message')) {
print 'ok';
}
}
And now, if i run this function, result is printed 'ok' on monitor.
But no mail is on my testing email box, even span, nothing.
My question is, why cakephp tells me that sending was done, but no mail is present on my box ?
Thank You.
Your configuration is incorrect. cakePHP attempts to send the e-mail via smtp to your localhost.
Most likely you do not have an MTA (ie. exim, dovecot) installed locally and the request gets dropped. This should be visible as an error in you logs (if enabled).
An easy solution is to change the configuration to a working email service for testing, for example Gmail.
Example:
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my#gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
Note that the host and port point to Gmail. This example is indicative and was taken from the official documentation.
More information on configuring email transports in cakePHP 3.0 here: http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports
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,
);
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.