本文整理匯總了PHP中CakeEmail::reset方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeEmail::reset方法的具體用法?PHP CakeEmail::reset怎麽用?PHP CakeEmail::reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CakeEmail
的用法示例。
在下文中一共展示了CakeEmail::reset方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processSend
public function processSend($data)
{
// set up email parameters
$subject = isset($data['subject']) ? $data['subject'] : 'Goalmine update';
// set up parameters
// add the checkbox values together to get all games
$game = array_sum($data['game']);
// do bitwise comparison of game field to select correct users
$arr = ['fields' => 'email', 'recursive' => 0, 'conditions' => __('games & %s != 0', $game)];
$users = $this->find('list', $arr);
foreach ($users as $k => &$u) {
if (filter_var($u, FILTER_VALIDATE_EMAIL)) {
$filtered_users[] = $u;
}
}
// the response. null if the email isnt sent
$res = null;
// set up the email object and send email
// recipients are single list in BCC field so only one email need be sent
try {
$email = new CakeEmail('default');
$email->from(MAIL_SENDER)->subject($subject)->to(MAIL_SENDER)->bcc($filtered_users);
$res = $email->send($data['body']);
} catch (SocketException $e) {
$this->log('Error in sending email');
}
$email->reset();
return is_null($res) ? null : count($users);
}
示例2: process
public function process()
{
$c = new CakeEmail('default');
//grab 50 emails
$emails = $this->EmailMessage->find("all", array("conditions" => array("EmailMessage.processed" => 0, "EmailMessage.to !=" => '', "NOT" => array("EmailMessage.to" => null)), "contain" => array()));
$total_emails = count($emails);
$this->out("emails to processes: " . $total_emails);
SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Emails to processes: " . $total_emails));
foreach ($emails as $email) {
$e = $email['EmailMessage'];
$c->reset();
$c->config('default');
$c->to($e['to']);
$c->subject($e['subject']);
$c->template($e['template']);
$c->viewVars(array("msg" => $email));
if ($c->send()) {
$this->EmailMessage->create();
$this->EmailMessage->id = $e['id'];
$this->EmailMessage->save(array("processed" => 1, "sent_date" => DboSource::expression('NOW()')));
$total_emails--;
$this->out("Email:" . $e['to'] . " Template: " . $e['template']);
} else {
$this->out("Email failed: " . $e['id']);
SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Email Failed: " . $e['id']));
}
}
}
示例3: sendAll
public function sendAll($parentData = null, $newThreadId = null)
{
/* Send emails to all users subscribed to the thread $parentData['Thread']['id'] */
foreach ($this->find('all', array('conditions' => array('thread_id' => $parentData['Thread']['id']))) as $notification) {
if (AuthComponent::User('id') !== $notification['User']['id']) {
$email = new CakeEmail();
$email->config('noreply');
$email->template('thread_notification');
$email->viewVars(array('threadData' => $parentData, 'userId' => $notification['User']['id'], 'token' => $notification['Notification']['token'], 'author' => AuthComponent::User('username'), 'threadId' => $newThreadId, 'parentThreadId' => $parentData['Thread']['id'], 'threadTitle' => Inflector::slug($parentData['Thread']['title'], '-')));
$email->to($notification['User']['email']);
$email->subject('Reply to thread ' . $parentData['Thread']['title']);
$email->emailFormat('html');
$email->send();
$email->reset();
}
}
}
示例4: sendEmail
public function sendEmail($user, $body, $bodyNoEnc = false, $subject, $replyToUser = false)
{
$failed = false;
$failureReason = "";
// check if the e-mail can be encrypted
$canEncrypt = false;
if (isset($user['User']['gpgkey']) && !empty($user['User']['gpgkey'])) {
$canEncrypt = true;
}
// If bodyonlencrypted is enabled and the user has no encryption key, use the alternate body (if it exists)
if (Configure::read('GnuPG.bodyonlyencrypted') && !$canEncrypt && $bodyNoEnc) {
$body = $bodyNoEnc;
}
$body = str_replace('\\n', PHP_EOL, $body);
// Sign the body
require_once 'Crypt/GPG.php';
try {
$gpg = new Crypt_GPG(array('homedir' => Configure::read('GnuPG.homedir'), 'binary' => Configure::read('GnuPG.binary') ? Configure::read('GnuPG.binary') : '/usr/bin/gpg'));
// , 'debug' => true
$gpg->addSignKey(Configure::read('GnuPG.email'), Configure::read('GnuPG.password'));
$body = $gpg->sign($body, Crypt_GPG::SIGN_MODE_CLEAR);
} catch (Exception $e) {
$failureReason = " the message could not be signed. The following error message was returned by gpg: " . $e->getMessage();
$this->log($e->getMessage());
$failed = true;
}
// If we cannot encrypt the mail and the server settings restricts sending unencrypted messages, return false
if (!$failed && !$canEncrypt && Configure::read('GnuPG.onlyencrypted')) {
$failed = true;
$failureReason = " encrypted messages are enforced and the message could not be encrypted for this user as no valid encryption key was found.";
}
// Let's encrypt the message if we can
if (!$failed && $canEncrypt) {
$keyImportOutput = $gpg->importKey($user['User']['gpgkey']);
try {
$gpg->addEncryptKey($keyImportOutput['fingerprint']);
// use the key that was given in the import
$body = $gpg->encrypt($body, true);
} catch (Exception $e) {
// despite the user having a PGP key and the signing already succeeding earlier, we get an exception. This must mean that there is an issue with the user's key.
$failureReason = " the message could not be encrypted because there was an issue with the user's PGP key. The following error message was returned by gpg: " . $e->getMessage();
$this->log($e->getMessage());
$failed = true;
}
}
$replyToLog = '';
if (!$failed) {
$Email = new CakeEmail();
// If the e-mail is sent on behalf of a user, then we want the target user to be able to respond to the sender
// For this reason we should also attach the public key of the sender along with the message (if applicable)
if ($replyToUser != false) {
$Email->replyTo($replyToUser['User']['email']);
if (!empty($replyToUser['User']['gpgkey'])) {
$Email->attachments(array('gpgkey.asc' => array('data' => $replyToUser['User']['gpgkey'])));
}
$replyToLog = 'from ' . $replyToUser['User']['email'];
}
$Email->from(Configure::read('MISP.email'));
$Email->to($user['User']['email']);
$Email->subject($subject);
$Email->emailFormat('text');
$result = $Email->send($body);
$Email->reset();
}
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
if (!$failed && $result) {
$this->Log->save(array('org' => 'SYSTEM', 'model' => 'User', 'model_id' => $user['User']['id'], 'email' => $user['User']['email'], 'action' => 'email', 'title' => 'Email ' . $replyToLog . ' to ' . $user['User']['email'] . ' sent, titled "' . $subject . '".', 'change' => null));
return true;
} else {
if (isset($result) && !$result) {
$failureReason = " there was an error sending the e-mail.";
}
$this->Log->save(array('org' => 'SYSTEM', 'model' => 'User', 'model_id' => $user['User']['id'], 'email' => $user['User']['email'], 'action' => 'email', 'title' => 'Email ' . $replyToLog . ' to ' . $user['User']['email'] . ', titled "' . $subject . '" failed. Reason: ' . $failureReason, 'change' => null));
}
return false;
}
示例5: resetAndSet
/**
* EmailLib::resetAndSet()
*
* @return void
*/
public function resetAndSet($config = null)
{
if ($config === null) {
$config = 'default';
}
parent::reset();
$this->_priority = null;
$this->_wrapLength = null;
$this->_log = null;
$this->_error = null;
$this->_debug = null;
$this->_applyConfig($config);
if ($fromEmail = Configure::read('Config.systemEmail')) {
$fromName = Configure::read('Config.systemName');
} else {
$fromEmail = Configure::read('Config.adminEmail');
$fromName = Configure::read('Config.adminName');
}
if (!$fromEmail) {
throw new RuntimeException('You need to either define Config.systemEmail or Config.adminEmail in Configure.');
}
$this->from($fromEmail, $fromName);
if ($xMailer = Configure::read('Config.xMailer')) {
$this->addHeaders(['X-Mailer' => $xMailer]);
}
}
示例6: reset
public function reset()
{
parent::reset();
$this->error = '';
$this->_debug = null;
}