本文整理汇总了PHP中EmailMessage::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailMessage::getErrors方法的具体用法?PHP EmailMessage::getErrors怎么用?PHP EmailMessage::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailMessage
的用法示例。
在下文中一共展示了EmailMessage::getErrors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareMessageContent
/**
* Prepare message content.
* @param EmailMessage $emailMessage
* @return string
*/
public static function prepareMessageContent(EmailMessage $emailMessage)
{
$messageContent = null;
if (!($emailMessage->hasErrors() || $emailMessage->hasSendError())) {
$messageContent .= Zurmo::t('EmailMessagesModule', 'Message successfully sent') . "\n";
} else {
$messageContent .= Zurmo::t('EmailMessagesModule', 'Message failed to send') . "\n";
if ($emailMessage->hasSendError()) {
$messageContent .= $emailMessage->error . "\n";
} else {
//todo: refactor to use ZurmoHtml::errorSummary after this supports that method
//todo: supports nested messages better.
$errors = $emailMessage->getErrors();
foreach ($errors as $attributeNameWithErrors) {
foreach ($attributeNameWithErrors as $attributeError) {
if (is_array($attributeError)) {
foreach ($attributeError as $nestedAttributeError) {
$messageContent .= reset($nestedAttributeError) . "\n";
}
} else {
$messageContent .= reset($attributeError) . "\n";
}
}
}
}
}
return $messageContent;
}
示例2: actionSend
/**
* Execute the action.
* @param array command line parameters specific for this command
*/
public function actionSend($username, $toAddress, $subject = 'A test email from Zurmo', $textContent = 'A test text message from Zurmo.', $htmlContent = 'A test html message from Zurmo.', $host = null, $port = null, $outboundUsername = null, $outboundPassword = null, $outboundSecurity = null)
{
if (!isset($username)) {
$this->usageError('A username must be specified.');
}
if (!isset($toAddress)) {
$this->usageError('You must specify a to address.');
}
try {
Yii::app()->user->userModel = User::getByUsername($username);
} catch (NotFoundException $e) {
$this->usageError('The specified username does not exist.');
}
if ($host != null) {
Yii::app()->emailHelper->outboundHost = $host;
}
if ($port != null) {
Yii::app()->emailHelper->outboundPort = $port;
}
if ($outboundUsername != null) {
Yii::app()->emailHelper->outboundUsername = $outboundUsername;
}
if ($outboundUsername != null) {
Yii::app()->emailHelper->outboundPassword = $outboundPassword;
}
if ($outboundSecurity != null && $outboundSecurity != '' && $outboundSecurity != 'false') {
Yii::app()->emailHelper->outboundSecurity = $outboundSecurity;
} else {
Yii::app()->emailHelper->outboundSecurity = null;
}
echo "\n";
echo 'Using type:' . Yii::app()->emailHelper->outboundType . "\n";
echo 'Using host:' . Yii::app()->emailHelper->outboundHost . "\n";
echo 'Using port:' . Yii::app()->emailHelper->outboundPort . "\n";
echo 'Using username:' . Yii::app()->emailHelper->outboundUsername . "\n";
echo 'Using password:' . Yii::app()->emailHelper->outboundPassword . "\n";
if (isset(Yii::app()->emailHelper->outboundSecurity)) {
echo 'Using outbound security:' . Yii::app()->emailHelper->outboundSecurity . "\n\n";
} else {
echo 'Using outbound security: none' . "\n\n";
}
echo 'Sending Email Message' . "\n";
$emailMessage = new EmailMessage();
$emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
$emailMessage->subject = $subject;
$emailContent = new EmailMessageContent();
$emailContent->textContent = $textContent;
$emailContent->htmlContent = $htmlContent;
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel);
$sender->fromName = strval(Yii::app()->user->userModel);
$sender->personOrAccount = Yii::app()->user->userModel;
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = $toAddress;
$recipient->toName = 'Test Recipient';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
$validated = $emailMessage->validate();
if (!$validated) {
$this->addErrorsAsUsageErrors($emailMessage->getErrors());
}
Yii::app()->emailHelper->sendImmediately($emailMessage);
if (!$emailMessage->hasSendError()) {
echo Zurmo::t('Commands', 'Message successfully sent') . "\n";
} else {
echo Zurmo::t('Commands', 'Message failed to send') . "\n";
echo $emailMessage->error . "\n";
}
$saved = $emailMessage->save();
if (!$saved) {
throw new NotSupportedException();
}
}
示例3: resolveEmailMessage
protected function resolveEmailMessage($subject = 'Subject', $textContent = 'My First Message', $htmlContent = 'Some fake HTML content', $fromAddress = 'zurmo@zurmo.org', $fromName = 'Zurmo', $toAddress = 'bob.message@zurmotest.com', $toName = null, $contact = null)
{
if (!isset($contact)) {
$contact = ContactTestHelper::createContactByNameForOwner('emailContact', Yii::app()->user->userModel);
}
$emailMessage = new EmailMessage();
$emailMessage->owner = $contact->owner;
$emailMessage->subject = $subject;
$emailContent = new EmailMessageContent();
$emailContent->textContent = $textContent;
$emailContent->htmlContent = $htmlContent;
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = $fromAddress;
$sender->fromName = $fromName;
$sender->personsOrAccounts->add(Yii::app()->user->userModel);
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = $toAddress;
if (!isset($toName)) {
$toName = strval($contact);
}
$recipient->toName = $toName;
$recipient->personsOrAccounts->add($contact);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$emailBox = EmailBoxUtil::getDefaultEmailBoxByUser(Yii::app()->user->userModel);
$emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_OUTBOX);
$saved = $emailMessage->save();
if (!$saved) {
var_dump($emailMessage->getErrors());
throw new FailedToSaveModelException();
}
return $emailMessage;
}
示例4: testMultipleRecipientsAndTypes
/**
* @depends testCreateAndSendEmailMessageWithAttachment
*/
public function testMultipleRecipientsAndTypes()
{
$billy = User::getByUsername('billy');
$jane = User::getByUsername('jane');
$sally = User::getByUsername('sally');
$jason = User::getByUsername('jason');
$this->assertEquals(3, EmailMessage::getCount());
$emailMessage = new EmailMessage();
$emailMessage->owner = $jane;
$emailMessage->subject = 'My Third Email';
//Attempt to save without setting required information
$saved = $emailMessage->save();
$this->assertFalse($saved);
$compareData = array('folder' => array('name' => array('Name cannot be blank.'), 'emailBox' => array('name' => array('Name cannot be blank.'))), 'sender' => array('fromAddress' => array('From Address cannot be blank.')));
$this->assertEquals($compareData, $emailMessage->getErrors());
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My Third Message';
$emailMessage->content = $emailContent;
//Sending from jane
$sender = new EmailMessageSender();
$sender->fromAddress = 'jane@fakeemail.com';
$sender->fromName = 'Jane Smith';
$sender->personsOrAccounts->add($jane);
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($billy);
$emailMessage->recipients->add($recipient);
//CC recipient is Sally
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'sally@fakeemail.com';
$recipient->toName = 'Sally Pail';
$recipient->type = EmailMessageRecipient::TYPE_CC;
$recipient->personsOrAccounts->add($sally);
$emailMessage->recipients->add($recipient);
//BCC recipient is Jason
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'jason@fakeemail.com';
$recipient->toName = 'Jason Blue';
$recipient->type = EmailMessageRecipient::TYPE_BCC;
$recipient->personsOrAccounts->add($jason);
$emailMessage->recipients->add($recipient);
//At this point the message is not in a folder.
$this->assertTrue($emailMessage->folder->id < 0);
$box = EmailBox::resolveAndGetByName('JaneBox');
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
//Save, at this point the email should be in the draft folder
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertTrue($emailMessage->folder->id > 0);
//Now send the message.
Yii::app()->emailHelper->send($emailMessage);
}