我想将我的 SMTP 凭据保存到 global.php 和 local.php 中,以便在生成邮件时调用它们,例如 db 适配器。最终,我将存储 smtp1 和 smtp2。我想避免将我的 SMTP 凭据保存在一个类中。
我的电子邮件类中的传统 SMTP 选项:
.............
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'smtp.gmail.com',
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'username' => 'secretusr',
'password' => 'secretpsw',
'ssl' => 'tls'
),
));
将它们保存到 global.php 中:
<?php
return array(
'db' => array(
'driver' => 'Pdo_Mysql',
'charset' => 'utf-8',
'dsn' => 'mysql:dbname=zftutorial;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'smtp'=> array(
'name' => 'smtp.gmail.com',
'host' => 'smtp.gmail.com',
'connection_class' => 'login'
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
'session' => array(
'config' => array(
'class' => 'Zend\Session\Config\SessionConfig',
'options' => array(
'name' => 'zf-tutorial',
),
),
'storage' => 'Zend\Session\Storage\SessionArrayStorage',
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
),
),
);
?>
用户名和密码保存到 local.php
return array(
'db' => array(
'username' => 'secretusr',
'password' => 'secretpsw',
),
'smtp' => array (
'connection_config' => array(
'username' => 'secretusr',
'password' => 'secretpsw',
'ssl' => 'tls'
),
),
);
如何调用先前保存的 smtp 凭据?在我的电子邮件课程中:
.......
$transport = new SmtpTransport();
$options = new SmtpOptions(**method to call global and local credential**);
$transport->setOptions($options);
$transport->send($message);
谢谢您的帮助!