简体   繁体   English

Cakephp 3电子邮件

[英]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 我正在尝试使用cakephp从我的用户发送电子邮件,但是我希望每个用户都使用他们自己的电子邮件,例如我的应用程序配置

'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. 它用于App电子商店,例如accont恢复和注册。

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...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM