How to set up a smtp connection on a domain email in laravel - email

I have a domain: www.mydomain.ro and i created an email like this: office#mydomain.ro
I'm trying to send emails from my laravel application(laravel 5.7) and i did this configurations:
In .env file:
MAIL_DRIVER=smtp
MAIL_HOST=office#my-domain.ro
MAIL_PORT=26
MAIL_USERNAME=office#my-domain.ro
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null
And in config/mail.php:
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mail.my-domain.ro '),
'port' => env('MAIL_PORT', 26),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'office#muy-domain.ro'),
'name' => env('MAIL_FROM_NAME', 'Office my-domain'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('office#my-domain.ro'),
'password' => env('mypassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
In Controller i'm doing this:
$data = array(
'name' => 'Ioan Andrei',
'body' => 'Test Email'
);
Mail::send('emails.demandreceived',$data,function ($message){
$message->from('office#my-domain.ro','TEST');
$message->to('ioan.andrei97#gmail.com');
$message->subject('Test email');
I get this error:
Connection could not be established with host office#msipremiumcars.ro [php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known #0]
What am i doing wrong?It's not working beacuse i'm trying to send them from my local server?
Can i use mailgun for example to send the email and still have the email send from office#mydomain.ro?
I tried to restart my local server after configs.
Laravel version: 5.7

The issue is the MAIL_HOST in the .env file. It needs to be hostname like my-domain.ro instead of an email address as you've currently entered office#my-domain.ro.

Related

yii2 mailer smtp connection refused

When setting up my smtp mailer in the config file, it works fine. But if I manually create the SMPT mailer it fails (Connection refused). Can anybody assist?
Yii2 config file:
'components'=[
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
The following code in my controller does not work:
$mailer = new \yii\swiftmailer\Mailer();
$mailer->transport = new \Swift_SmtpTransport();
$mailer->transport
->setHost('smtp.gmail.com')
->setPort(587)
->setEncryption('tls');
$mailer->transport->setUsername('email#gmail.com');
$mailer->transport->setPassword('password');
and I receive an error message: Connection refused #111
I have tried port 465 on ssl and I receive the same message.
My main reason for doing this is that I have different client accounts, each of which has its own smtp. I therefore need one account per client and I cannot seem to do that via the config file.
Many thanks for your help.
I just tried it worked for me, I did as follow
'components'=[
'mailer' => [ //Your default mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
'mailer2' => [ //Your custom mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'new_email#gmail.com',
'password' => 'new_password',
'port' => 'new_port587',
'encryption' => 'new_tls',
],
]
following is for default config
Yii::$app->mailer->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
following with custom mailer config
Yii::$app->mailer2->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
create a component is the fastest solution, otherwise, you can use the parameter to store configuration, and call when needed.

CakePHP 3 Email Transport - Godaddy with Gmail

I don't know how to troubleshoot this. It works locally but not on my godaddy server. Where can I get all my variable options for SSL
I found an answer here I want to try
PHPMailer GoDaddy Server SMTP Connection Refused
It says I have to use
SMTP_SERVER: smtpout.secureserver.net (or alternatively relay-hosting.secureserver.net)
SMTP_PORT: 465 //or 3535 or 80 or 25
SMTP_AUTH: true //always
SMTP_Secure: 'ssl' //only if using port 465
How do I set these values with the transport.
I know port is 'port' and 'SMTP_SERVER' is 'host'
but is 'SMTP_AUTH', 'auth'?
/*Email Transport*/
'EmailTransport' => [
'gmail' => [
'host' => 'ssl://smtp.gmail.com',
//'host' => 'relay-hosting.secureserver.net',
//'host' => 'ASPMX.L.GOOGLE.COM',
//'host'=>'smtpout.secureserver.net',
'port' => 465,
'username' => '-----#gmail.com',
'password' => 'password',
'className' => 'Smtp',
'log' => true,
],
],
'Email' => [
'default' => [
'transport' => 'gmail'
],
I think that you cannot set that option in the array because the SMTP Transport class handles it internally. Check the code please of the class.
https://api.cakephp.org/3.3/source-class-Cake.Mailer.Transport.SmtpTransport.html#241-268
This works fine here. CakePHP will automatically use SMTP AUTH when you specify username and password. SSL will be used by prefixing the host with ssl:// and the appropriate port as you did.
'Email' => [
'default' => [
'transport' => 'gmail'
]
],
'EmailTransport' => [
'gmail' => [
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'googleUserNameWithout', //without the #gmail.com
'password' => 'P4ssw0rd',
'className' => 'Smtp'
]
]

Cakephp 3 email

I'm trying to use cakephp to send e-mail from my users, but I want each user uses they own e-mail for example
my app config
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'formulariosdsds#gmail.com',
'password' => '***',
'tls' => true,
],
it's used for App e-mais like, accont recovery and registration.
I want the users send with they own e-mail using the app like a transporter for each user. is there a way to do it?
Sure, you have to create a configuration transport each time a user send an email.
$transport = $user_data_email_config;
// first you drop to prevent to add a configuration pre existing and generate an error
Email::dropTransport($transport->name);
// now you create a custom configuration
Email::configTransport($transport->name, [
'className' => $transport->class_name,
'host' => $transport->host,
'port' => $transport->port,
'timeout' => 30,
'username' => $transport->username,
'password' => $transport->password,
'client' => $transport->client,
'tls' => $transport->tls
]);
$Email = new Email();
// for use the custom configuration, set the transport providing the transport name when you configure the email.
$Email->transport($transport->name);
// the rest of email configuration...

Do you have any idea on how to implement efax using SMTP Mail Driver (MAILGUN)

This is the sample email I received
This is my code:
Laravel 4.2
Controller:
Mail::send('emails.patient.fax-note'){
$message->to('61756041159#efaxsend.com');
$message->to('sunnycris1229#gmail.com', "Sunny");
$message->subject('Test Fax Notes Using smtp.mailgun.org');
$message->from('support#lktconsult.com');
} , "-f support#lktconsult.com");
mail.php setting
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => "support#lktconsult.com", 'name' => "Hippocamp"),
'encryption' => 'tls',
'username' => "support#lktconsult.com",
'password' => "mypassword",
services.php
'mailgun' => array(
'domain' => 'sandbox9a694deec43645249032794f0b054c82.mailgun.org',
'secret' => 'my key here',
),
My Code works perfectly in the email, but not in efax, because efax only accept the mail if you send it to :61756041159#efaxsend.com and most importantly from: support#lktconsult.com , My problem is, the image I attached is the original email I received in my gmail.. stating that it came from : Received: from mail1.static.mgsend.net (mail1.static.mgsend.net. [104.130.122.1]) thats why efax does not accept the email.

Cakephp 2.x Mail connection with Office365

I am developing an application where my client is using Office 365 for his emails , etc... I am trying to connect Cakephp mail with office 365 SMTP but without any success.
Here is my code:
public $default = array(
'from' => array('info#*****.com' => 'Company Name'),
'transport' => 'Smtp',
'host' => 'tls://smtp.office365.com',
'port' => 587,
'username' => 'info#*****.com',
'password' => '*******',
'client' => null,
'log' => true,
'tls' => true
);
The error iam getting is Unable to connect to SMTP server. Also I tried the following hosts with and without tls:
ssl://smtp-mail.outlook.com
Smtp.mail.apac.microsoftonline.com (on this i was getting timeout error)
pod51022.outlook.com
Thanks.
try following :
'public $default = array(
'host' => 'smtp.office365.com',
'port' =>25,
'from' => array('info#*****.com' => 'Company Name'),
'transport' => 'Smtp',
'username' => 'info#*****.com',
'password' => '*******',
'tls'=>true );'
in case it don't work,
try after removing password,
make sure that
email id is authenticated to send anonymous mail on office365.