本文整理汇总了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);
}
//.........这里部分代码省略.........