我正在尝试从mail.local.php获取配置smtp,但我确实尝试过ServiceLoader
getServiceLoader
方法,但无法在助手类中找到获取配置的方法:
获得autoload\mail.local.php
的最佳方法是什么,
namespace Helpers;
use Zend\Mail;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
class SendEmail
{
public static function email($to = '', $recipientName = '', $template = '')
{
$transport = new SmtpTransport();
// $options = new SmtpOptions(array(
// 'name' => 'smtp.mailtrap.io',
// 'host' => 'smtp.mailtrap.io',
// 'port' => 2525,
// 'connection_class' => 'crammd5',
// 'connection_config' => array(
// 'username' => 'f11f5a55fdfbf5',
// 'password' => '7780e1e7ee1cc5',
// ),
// ));
$mail = new Mail\Message();
$html = new \Zend\Mime\Part($template);
$html->type = 'text/html';
$body = new \Zend\Mime\Message;
$body->setParts(array($html));
$mail->setBody($body);
$mail->setFrom('[email protected]', 'Admin FoneDoctors');
$mail->addTo($to, $recipientName);
$mail->setSubject('Unpaid Invoices');
$transport->setOptions($options);
$transport->send($mail);
}
}
如果您的配置文件位于/autoload/mail.local.php
中,则该配置将作为ZF引导过程的一部分进行合并。然后可以使用$serviceManager->get('config');