简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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