當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。