本文整理汇总了PHP中Swift_SmtpTransport::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_SmtpTransport::send方法的具体用法?PHP Swift_SmtpTransport::send怎么用?PHP Swift_SmtpTransport::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_SmtpTransport
的用法示例。
在下文中一共展示了Swift_SmtpTransport::send方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Sends the given message.
*
* The return value is the number of recipients who were accepted for
* delivery.
*
* @param \Swift_Mime_Message $message
* @param array $failedRecipients An array of failures by-reference
*
* @return int The number of recipients who were accepted for delivery
* @throws \Exception
*/
public function send(\Swift_Mime_Message $message, &$failedRecipients = null)
{
$result = 0;
// start a transport if needed
$needToStopRealTransport = false;
if (!$this->getTransport()->isStarted()) {
$this->getTransport()->start();
$needToStopRealTransport = true;
}
// send a mail
$sendException = null;
try {
if ($this->smtpTransport) {
$result = $this->smtpTransport->send($message, $failedRecipients);
} else {
$result = parent::send($message, $failedRecipients);
}
} catch (\Exception $unexpectedEx) {
$sendException = $unexpectedEx;
}
// stop a transport if it was started before
if ($needToStopRealTransport) {
try {
$this->getTransport()->stop();
} catch (\Exception $ex) {
// ignore errors here
}
}
// rethrow send failure
if ($sendException) {
throw $sendException;
}
return $result;
}
示例2: send
/**
* @param \Swift_Mime_Message $message
* @param null $failedRecipients
*
* @return int
* @throws \Exception
*/
public function send(\Swift_Mime_Message $message, &$failedRecipients = null)
{
$this->message = $message;
$this->prepareMessage();
return parent::send($message, $failedRecipients);
}
示例3: testEmailServerConnectionAction
/**
* Tests mail transport settings
*
* @param Request $request
*
* @return JsonResponse
*/
protected function testEmailServerConnectionAction(Request $request)
{
$dataArray = array('success' => 0, 'error' => '');
if ($this->factory->getUser()->isAdmin()) {
$settings = $request->request->all();
$transport = $settings['transport'];
switch ($transport) {
case 'mautic.transport.mandrill':
$mailer = new MandrillTransport();
break;
case 'mautic.transport.sendgrid':
$mailer = new SendgridTransport();
break;
case 'mautic.transport.amazon':
$mailer = new AmazonTransport();
break;
case 'mautic.transport.postmark':
$mailer = new PostmarkTransport();
break;
case 'gmail':
$mailer = new \Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl');
break;
case 'smtp':
$mailer = new \Swift_SmtpTransport($settings['host'], $settings['port'], $settings['encryption']);
break;
}
if (!empty($mailer)) {
if (empty($settings['password'])) {
$settings['password'] = $this->factory->getParameter('mailer_password');
}
$mailer->setUsername($settings['user']);
$mailer->setPassword($settings['password']);
$logger = new \Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
try {
$mailer->start();
$translator = $this->factory->getTranslator();
if ($settings['send_test'] == 'true') {
$message = new \Swift_Message($translator->trans('mautic.core.config.form.mailer.transport.test_send.subject'), $translator->trans('mautic.core.config.form.mailer.transport.test_send.body'));
$user = $this->factory->getUser();
$message->setFrom(array($settings['from_email'] => $settings['from_name']));
$message->setTo(array($user->getEmail() => $user->getFirstName() . ' ' . $user->getLastName()));
$mailer->send($message);
}
$dataArray['success'] = 1;
$dataArray['message'] = $translator->trans('mautic.core.success');
} catch (\Exception $e) {
$dataArray['message'] = $e->getMessage() . '<br />' . $logger->dump();
}
}
}
return $this->sendJsonResponse($dataArray);
}