Cakephp 3 email - 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...

Related

smtp not working on 1and1

I'm using 1and1 server to host my CakePHP 3.2 application
This is how, I have configured email component on CakePHP
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'smtp.1and1.com',
'port' => 587,
'timeout' => 30,
'username' => 'noreply#mywebsite.com',
'password' => 'password',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
But this is not working and no email is sent and gives Connection Time out after 30 seconds.
From 1and1 email configuration page. It says
Outgoing port (TLS must be activated)
How to enable/configure TLS in CakePHP ?
Edit 2
the error stack shows
SmtpTransport.php
protected function _connect()
{
$this->_generateSocket();
if (!$this->_socket->connect()) { // marked this line
throw new SocketException('Unable to connect to SMTP server.');
}
$this->_smtpSend(null, '220');
Action to send email
public function sendEmail($user_id = null, $email_id = null, $hash = null, $request = null)
{
switch($request) {
case 'register' : $subject = 'Account Confirmation';
$message = 'You have successfully registered. Click below link to verify it http://website.com/sellers/verify/'.$email_id.'/'.$hash;
break;
}
$email = new Email('default');
if ($email->from(['anujsharma9196#gmail.com' => 'Argo Systems'])
->to((string)$email_id)
->subject($subject)
->send($message)) {
return true;
} else {
return false;
}
}
and calling this function from same controller by
$this->sendEmail($user->id, $user->email, $hash, 'register');
from the manual (bold is mine)
You can configure SSL SMTP servers, like Gmail. To do so, put the ssl:// prefix in the host and configure the port value accordingly. You can also enable TLS SMTP using the tls option:
so just set
'tls' => true
in your configuration array and try if it works
Edit
following this page I found that you don't even need to use the Smtp transporter
just use a simple Mail transporter this way
'default' => [
'className' => 'Mail'
]
There is no need to supply a username, password, or specify which mail server should be used to send the mail since this information is already contained in PHP variables.
try that!
I used below configuration in system for mail using gmail. it work fine. you just try with your server.
'EmailTransport' => [
'default' => [
'className' => 'SMTP',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 100,
'username' => 'example#gmail.com',
'password' => 'exmple123',
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
Check with your port and host.Hope fully it will works
Try
Thanks

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.

Yii2 Signup Email option

How can I set up automatic email for signup activation link in yii 2.0.3 advanced application template and how link back to login page
in this new version?
Configure the Swiftmailer in common\config\main.php components array:
// for sending mail using swift mailer
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'your_host_name',
'username' => 'enter_your_username_here',
'password' => 'enter_your_password',
'port' => '25',
],
],
After this you can use the following code to send mails:
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
->setFrom('from#domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
contact/html is the template name which is there is common/mail folder and contactForm variable having value $form is passed to that template.
You can put the above code in your controller. But I will suggest make a commonfunction of it and use it from anywhere. Hope it helps.

cakephp email issue with some domains

I have cakephp application, and it has no domain name we are accessing using ip.
I am using the following smpt setting to send email
class EmailConfig {
public $smtp = array(
'transport' => 'Smtp',
'from' => array('myemail#otherdomain.com' => 'my name'),
'host' => 'mail.otherdomain.com',//not the same domain from which sending email
'port' => 25,
'timeout' => 30,
'username' => 'myemail#otherdomain.com',
'password' => 'password',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
all emails are being sent to any_email # gmail, otherdomain etc
but there is only one specific govt domain(abc.gov.com) who are not receiving email
they may have implemented some security measures, which may prevent my emails to them, what things can I try at my side and how can I debug to get exact error.
I tried to send email where
to = email#abc.gov.com
cc = email#otherdomain.com
the same email is being received by email#otherdomain.com while not by email#abc.gov.com

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.