当前位置: 首页>>代码示例>>PHP>>正文


PHP eZMail::setReceiverElements方法代码示例

本文整理汇总了PHP中eZMail::setReceiverElements方法的典型用法代码示例。如果您正苦于以下问题:PHP eZMail::setReceiverElements方法的具体用法?PHP eZMail::setReceiverElements怎么用?PHP eZMail::setReceiverElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZMail的用法示例。


在下文中一共展示了eZMail::setReceiverElements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSendEmail

 /**
  * @dataProvider providerTestSendEmail
  */
 public function testSendEmail($sendData, $expectedResult)
 {
     if (empty($sendData)) {
         $this->markTestSkipped('No $sendData from data provider.');
     }
     if (!self::imapIsEnabled()) {
         $this->markTestSkipped('IMAP is not loaded');
         return;
     }
     $emailINI = eZINI::instance('test_ezmail_plain.ini');
     $mboxString = $emailINI->variable('TestAccounts', 'MBoxString');
     $recipients = array_merge((array) $sendData['to'], (array) $sendData['cc'], (array) $sendData['bcc']);
     if (isset($sendData['Transport']) and $sendData['Transport'] == 'SMTP') {
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'Transport', 'SMTP');
         $mailINI = eZINI::instance('test_ezmail_plain.ini');
         $mailSetting = $mailINI->group('MailSettings');
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportServer', $mailSetting['TransportServer']);
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportPort', $mailSetting['TransportPort']);
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportUser', $mailSetting['TransportUser']);
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportPassword', $mailSetting['TransportPassword']);
     }
     if (isset($sendData['DebugSending']) and $sendData['DebugSending'] == true) {
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'DebugSending', 'enabled');
         $users = self::getTestAccounts();
         $recipients[] = $users['01'];
     } else {
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'DebugSending', 'disabled');
     }
     foreach ($recipients as $recipient) {
         // Accept only testing accounts as recipients
         if (preg_match('/^ezp-unittests-\\d\\d\\@mail\\.ez\\.no$/', $recipient['email']) != 1) {
             $this->markTestSkipped('Refusing to use other than testing accounts');
             return;
         }
         // Open mailbox and delete all existing emails in the account
         $mbox = @imap_open($mboxString, $recipient['username'], $recipient['password']);
         if (!$mbox) {
             $this->markTestSkipped('Cannot open mailbox for ' . $recipient['username'] . ': ' . imap_last_error());
             return;
         }
         $status = imap_status($mbox, $mboxString, SA_MESSAGES);
         for ($i = 1; $i <= $status->messages; $i++) {
             imap_delete($mbox, $i);
         }
         imap_expunge($mbox);
         imap_close($mbox);
     }
     // Create and send email
     $mail = new eZMail();
     if (count($sendData['to']) == 1) {
         $mail->setReceiver($sendData['to'][0]['email'], $sendData['to'][0]['name']);
     } else {
         $mail->setReceiverElements($sendData['to']);
     }
     if ($sendData['replyTo']) {
         $mail->setReplyTo($sendData['replyTo']['email'], $sendData['replyTo']['name']);
     }
     $mail->setSender($sendData['sender']['email'], $sendData['sender']['name']);
     if ($sendData['cc']) {
         if (count($sendData['cc']) == 1) {
             $mail->addCc($sendData['cc'][0]['email'], $sendData['cc'][0]['name']);
         } else {
             $mail->setCcElements($sendData['cc']);
         }
     }
     if ($sendData['bcc']) {
         if (count($sendData['bcc']) == 1) {
             $mail->addBcc($sendData['bcc'][0]['email'], $sendData['bcc'][0]['name']);
         } else {
             $mail->setBccElements($sendData['bcc']);
         }
     }
     $mail->setSubject($sendData['subject']);
     $mail->setBody($sendData['body']);
     $sendResult = eZMailTransport::send($mail);
     $this->assertEquals(true, $sendResult);
     // Wait for it...
     sleep(2);
     // Read emails
     foreach ($recipients as $recipient) {
         $mbox = @imap_open($mboxString, $recipient['username'], $recipient['password']);
         if (!$mbox) {
             $this->markTestSkipped('Cannot open mailbox for ' . $recipient['username'] . ': ' . imap_last_error());
             return;
         }
         // Check message count before we try to open anything, in case nothing is there
         $status = imap_status($mbox, $mboxString, SA_MESSAGES);
         $this->assertEquals($expectedResult[$recipient['email']]['messageCount'], $status->messages);
         // Build actual result array, and check against the expected result
         $actualResult = array('messageCount' => $status->messages);
         for ($i = 1; $i <= $status->messages; $i++) {
             $headers = imap_headerinfo($mbox, $i);
             $actualResult['headers'] = array();
             $actualResult['headers']['to'] = array();
             foreach ($headers->to as $item) {
                 $actualResult['headers']['to'][] = array('email' => $item->mailbox . '@' . $item->host);
             }
//.........这里部分代码省略.........
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:101,代码来源:ezmail_test.php


注:本文中的eZMail::setReceiverElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。