本文整理汇总了PHP中App\Controller\AppController::sendEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP AppController::sendEmail方法的具体用法?PHP AppController::sendEmail怎么用?PHP AppController::sendEmail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Controller\AppController
的用法示例。
在下文中一共展示了AppController::sendEmail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterSave
public function afterSave(Event $event, Entity $entity)
{
$job_id = $entity->job_id;
$event_id = isset($entity->event_id) ? $entity->event_id : 1;
// default to event type 1 (new file upload)
// format file list, if applicable
$files = '';
if ($this->files) {
foreach ($this->files as $file) {
$files .= basename($file) . '<br/>';
}
}
// NEW FILE IS UPLOADED
if ($entity->isNew()) {
$Activity = TableRegistry::get('Activity');
$activity = $Activity->find('all')->where(['Activity.id' => $entity->id])->contain(['Files', 'Users', 'Creatives', 'Jobs'])->first()->toArray();
//die(print_r($activity));
$Notifications = TableRegistry::get('Notifications');
// set conditions for notification query
$conditions = ['OR' => [['Notifications.event_id' => "4"], ['Notifications.job_id' => $job_id, 'OR' => [['Notifications.event_id' => $event_id], ['Notifications.event_id' => "3"]]]]];
if ($notify_users = $Notifications->find('all', ['conditions' => $conditions, 'group' => ['Notifications.user_id'], 'contain' => ['Users']])) {
$notify_users = $notify_users->toArray();
$Events = TableRegistry::get('Events');
$event = $Events->get($event_id)->toArray();
$text = $event['email_text'];
$text = str_replace("%username%", $activity['user']['first_name'], $text);
$text = str_replace("%fileversion%", $activity['file']['version'], $text);
$text = str_replace("%filename%", $activity['file']['name'], $text);
$text = str_replace("%dimensions%", $activity['file']['width'] && $activity['file']['height'] ? $activity['file']['width'] . 'X' . $activity['file']['height'] : 'N/A', $text);
$text = str_replace("%size%", $activity['file']['size'], $text);
$text = str_replace("%jobname%", $activity['job']['name'], $text);
$text = str_replace("%joblink%", $activity['job']['short_link'] . '#' . $activity['creative']['slug'], $text);
$text = str_replace("%creativename%", $activity['creative']['name'], $text);
$text = str_replace("%files%", $files, $text);
$subject = $event['email_subject'];
$subject = str_replace("%filename%", $activity['file']['name'], $subject);
$subject = str_replace("%jobname%", $activity['job']['name'], $subject);
$subject = str_replace("%username%", $activity['user']['first_name'], $subject);
foreach ($notify_users as $user) {
$name = $user['user']['first_name'];
$email = $user['user']['email'];
$body = file_get_contents(WWW_ROOT . DS . 'email/notify.html');
$body = str_replace("%name%", $name, $body);
$body = str_replace("%username%", $name, $body);
$body = str_replace("%email%", $email, $body);
$body = str_replace("%text%", $text, $body);
if (AppController::sendEmail(['subject' => $subject, 'body' => $body, 'to' => $email])) {
$Notifications->save($Notifications->newEntity(['id' => $user['id']]));
} else {
// epic fail
}
}
}
}
}
示例2: forgot
public function forgot()
{
$message_sent = false;
$msg = false;
if ($this->request->is('post') && isset($this->request->data['email'])) {
$Users = TableRegistry::get('Users');
if ($user = $Users->find('all', ['conditions' => ['email' => $this->request->data['email']]])->first()) {
$user = $user->toArray();
// generate temp password and save to user
$tmp_pw = substr(md5(uniqid(rand(), true)), 0, 8);
$hashed = $this->create_hash($tmp_pw);
if ($Users->save($Users->newEntity(['id' => $user['id'], 'salt' => $hashed['salt'], 'hash' => $hashed['hash'], 'require_pw_change' => 1]))) {
// send email
$message = file_get_contents(Router::fullbaseUrl() . DS . 'email/forgot.html');
$message = str_replace("%name%", $user['first_name'], $message);
$message = str_replace("%email%", $user['email'], $message);
$message = str_replace("%password%", $tmp_pw, $message);
//send the message, check for errors
if (AppController::sendEmail(array('to' => $user['email'], 'bcc' => 'dlowetz@tagworldwide.com', 'subject' => 'TDI Preview Password Reset', 'body' => $message))) {
$message_sent = true;
}
}
} else {
$msg = 'Email address not on record';
}
}
$this->set(compact('msg', 'message_sent'));
}
示例3: cleanup
//.........这里部分代码省略.........
}
// read through library and match to DB records. Build an array of the file tree
$f = array();
$jobs = opendir($upload_dir);
while (($job = readdir($jobs)) !== false) {
// disregard system files and downloads folder
if ($job == '.' || $job == '..' || substr($job, 0, 1) == '.' || $job == 'downloads') {
continue;
} else {
// open directroy to view create folders
$creatives = opendir($upload_dir . DS . $job);
while (($creative = readdir($creatives)) !== false) {
// disregard system files and downloads folder
if ($creative == '.' || $creative == '..' || substr($creative, 0, 1) == '.') {
continue;
} else {
// open creatives to view files
$files = opendir($upload_dir . DS . $job . DS . $creative);
while (($file = readdir($files)) !== false) {
// disregard system files and downloads folder
if ($file == '.' || $file == '..' || substr($file, 0, 1) == '.' || $file == 'tmp' || $file == 'versions') {
continue;
} else {
$f[$job][$creative][] = $file;
// locate match in DB - delete if not found
if (!$Files->find('all', array('conditions' => array('archived' => 0, 'file' => $upload_dir . DS . $job . DS . $creative . DS . $file)))) {
$status[$upload_dir . DS . $job . DS . $creative . DS . $file][] = 'missing from database';
unlink($upload_dir . DS . $job . DS . $creative . DS . $file);
if (!file_exists($upload_dir . DS . $job . DS . $creative . DS . $file)) {
$status[$upload_dir . DS . $job . DS . $creative . DS . $file][] = 'deleted';
}
}
}
}
// open creatives to view tmp dir
if (is_dir($upload_dir . DS . $job . DS . $creative . DS . 'tmp')) {
$tmps = opendir($upload_dir . DS . $job . DS . $creative . DS . 'tmp');
while (($tmp_file = readdir($tmps)) !== false) {
// disregard system files and downloads folder
if ($tmp_file == '.' || $tmp_file == '..' || substr($tmp_file, 0, 1) == '.') {
continue;
} else {
$f[$job][$creative]['tmp'][] = $tmp_file;
// locate match in DB - delete if not found
if (!$Files->find('all', array('conditions' => array('archived' => 0, 'file' => $upload_dir . DS . $job . DS . $creative . DS . 'tmp' . $tmp_file)))) {
$status[$upload_dir . DS . $job . DS . $creative . DS . 'tmp' . $tmp_file][] = 'missing from database';
unlink($upload_dir . DS . $job . DS . $creative . DS . 'tmp' . DS . $tmp_file);
if (!file_exists($upload_dir . DS . $job . DS . $creative . DS . 'tmp' . DS . $tmp_file)) {
$status[$upload_dir . DS . $job . DS . $creative . DS . 'tmp' . $tmp_file][] = 'deleted';
}
}
}
}
}
// open versions to view versions dir
if (is_dir($upload_dir . DS . $job . DS . $creative . DS . 'versions')) {
$versions = opendir($upload_dir . DS . $job . DS . $creative . DS . 'versions');
while (($version_file = readdir($versions)) !== false) {
// disregard system files and downloads folder
if ($version_file == '.' || $version_file == '..' || substr($version_file, 0, 1) == '.') {
continue;
} else {
$v = str_replace("v_", "", $version_file);
$v = substr($v, 0, strpos($v, "_"));
$f[$job][$creative]['versions'][] = $version_file;
// the file's original name before being versioned (this is what is stored in the DB)
$path_name = $upload_dir . DS . $job . DS . $creative . DS . str_replace('v_' . $v . '_', "", $version_file);
// locate match in DB - delete if not found
if (!$Files->find('all', array('conditions' => array('archived' => 1, 'version' => $v, 'file' => $path_name)))) {
$status[$path_name][] = 'missing from database';
unlink($upload_dir . DS . $job . DS . $creative . DS . 'versions' . DS . $version_file);
if (!file_exists($upload_dir . DS . $job . DS . $creative . DS . 'versions' . DS . $version_file)) {
$status[$path_name][] = 'deleted';
}
}
}
}
}
}
}
}
}
closedir($jobs);
closedir($creatives);
closedir($tmps);
closedir($versions);
if (count($status) > 0) {
echo '<pre>';
print_r($status);
echo '</pre>';
$body = '';
foreach ($status as $key => $value) {
$body .= '<b>' . $key . '</b><br/>';
$body .= $value[0] . '<br/>';
$body .= $value[1] . '<br/><br/>';
}
AppController::sendEmail(array('to' => 'dlowetz@tagworldwide.com', 'subject' => 'TDI Preview Cleanup Crom', 'body' => $body));
}
$this->render(false);
}