本文整理汇总了PHP中email::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP email::connect方法的具体用法?PHP email::connect怎么用?PHP email::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email
的用法示例。
在下文中一共展示了email::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* The index method is the default method called when you access this controller, so we can use this
* to run the scheduled tasks. Takes an optional URL parameter "tasks", which is a comma separated list of
* the module names to schedule, plus can contain "notifications" to fire the built in notifications system or
* "all_modules" to fire every module that declares a scheduled task plugin.
* If tasks are not specified then everything is run.
*/
public function index()
{
$tm = microtime(true);
$this->db = new Database();
$system = new System_Model();
if (isset($_GET['tasks'])) {
$tasks = explode(',', $_GET['tasks']);
} else {
$tasks = array('notifications', 'all_modules');
}
// grab the time before we start, so there is no chance of a record coming in while we run that is missed.
$currentTime = time();
if (in_array('notifications', $tasks)) {
$this->last_run_date = $system->getLastScheduledTaskCheck();
$this->checkTriggers();
}
$tmtask = microtime(true) - $tm;
if ($tmtask > 5) {
self::msg("Triggers & notifications scheduled task took {$tmtask} seconds.", 'alert');
}
$this->runScheduledPlugins($system, $tasks);
if (in_array('notifications', $tasks)) {
$swift = email::connect();
$this->doRecordOwnerNotifications($swift);
$this->doDigestNotifications($swift);
}
// mark the time of the last scheduled task check, so we can get diffs next time
$this->db->update('system', array('last_scheduled_task_check' => "'" . date('c', $currentTime) . "'"), array('id' => 1));
self::msg("Ok!");
$tm = microtime(true) - $tm;
if ($tm > 30) {
self::msg("Scheduled tasks for " . implode(', ', $tasks) . " took {$tm} seconds.", 'alert');
}
}
示例2: send
/**
* Send an email message.
*
* @param string|array recipient email (and name), or an array of To, Cc, Bcc names
* @param string|array sender email (and name)
* @param string message subject
* @param string message body
* @param boolean send email as HTML
* @return integer number of emails sent
*/
public static function send($to, $from, $subject, $body, $html = TRUE)
{
// Connect to SwiftMailer
email::$mail === NULL and email::connect();
// Determine the message type
$html = $html === TRUE ? 'text/html' : 'text/plain';
// Create the message
$message = Swift_Message::newInstance()->setBody($body, $html)->setSubject($subject);
if (is_string($to)) {
// Single recipient
$message->setTo(array($to));
} elseif (is_array($to)) {
//array('to', array('address' => 'name'))
//array('to', 'address')
foreach ($to as $method => $add) {
switch (strtolower($method)) {
case 'bcc':
$message->setBcc($add);
break;
case 'cc':
$message->setCc($add);
break;
//Default method is to
//Default method is to
default:
$message->setTo($add);
break;
}
}
}
$message->setFrom($from);
return email::$mail->send($message);
}
示例3: send
/**
* Send an email message.
*
* @param string|array recipient email (and name), or an array of To, Cc, Bcc names
* @param string|array sender email (and name), or an array of From, Reply-To, Return-Path names
* @param string message subject
* @param string message body
* @param boolean send email as HTML
* @return integer number of emails sent
*/
public static function send($to, $from, $subject, $message, $html = FALSE)
{
// Connect to SwiftMailer
email::$mail === NULL and email::connect();
// Determine the message type
$html = $html === TRUE ? 'text/html' : 'text/plain';
// Create the message
$message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8');
if (is_string($to)) {
// Single recipient
$recipients = new Swift_Address($to);
} elseif (is_array($to)) {
if (isset($to[0]) and isset($to[1])) {
// Create To: address set
$to = array('to' => $to);
}
// Create a list of recipients
$recipients = new Swift_RecipientList();
foreach ($to as $method => $set) {
if (!in_array($method, array('to', 'cc', 'bcc'), TRUE)) {
// Use To: by default
$method = 'to';
}
// Create method name
$method = 'add' . ucfirst($method);
if (is_array($set)) {
// Add a recipient with name
$recipients->{$method}($set[0], $set[1]);
} else {
// Add a recipient without name
$recipients->{$method}($set);
}
}
}
if (is_array($from) and isset($from['from'])) {
foreach (array('reply-to' => 'setReplyTo', 'return-path' => 'setReturnPath') as $key => $method) {
if (isset($from[$key])) {
$address = is_array($from[$key]) ? $from[$key] + array(NULL, NULL) : array($from[$key], NULL);
$message->{$method}(new Swift_Address($address[0], $address[1]));
}
}
$from = $from['from'];
}
if (is_string($from)) {
// From without a name
$from = new Swift_Address($from);
} elseif (is_array($from)) {
// Make sure both indicies are set
$from = $from + array(NULL, NULL);
// From with a name
$from = new Swift_Address($from[0], $from[1]);
}
return email::$mail->send($message, $recipients, $from);
}
示例4: send
/**
* Send an email message.
*
* @param string|array $to recipient email (and name), or an array of To, Cc, Bcc names
* @param string|array $from sender email (and name)
* @param string $subject message subject
* @param string $message body
* @param boolean $html send email as HTML
* @param string|array $reply_to reply-to address (and name)
* @return integer number of emails sent
*/
public static function send($to, $from, $subject, $message, $html = false, $reply_to = null)
{
// Connect to SwiftMailer
Email::$mail === NULL and email::connect();
// Determine the message type
$html = $html === TRUE ? 'text/html' : 'text/plain';
// Create the message
$message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
if (is_string($to)) {
// Single recipient
$message->setTo($to);
} elseif (is_array($to)) {
if (isset($to[0]) and isset($to[1])) {
// Create To: address set
$to = array('to' => $to);
}
foreach ($to as $method => $set) {
if (!in_array($method, array('to', 'cc', 'bcc'), true)) {
// Use To: by default
$method = 'to';
}
// Create method name
$method = 'add' . ucfirst($method);
if (is_array($set)) {
// Add a recipient with name
$message->{$method}($set[0], $set[1]);
} else {
// Add a recipient without name
$message->{$method}($set);
}
}
}
if (is_string($from)) {
// From without a name
$message->setFrom($from);
} elseif (is_array($from)) {
// From with a name
$message->setFrom($from[0], $from[1]);
}
if (is_string($reply_to)) {
// Reply to without a name
$message->setReplyTo($reply_to);
} elseif (is_array($reply_to)) {
// Reply to with a name
$message->setReplyTo($reply_to[0], $reply_to[1]);
}
return Email::$mail->send($message);
}
示例5: send_email
private function send_email($email, $subject, $content)
{
$swift = email::connect();
$from = 'no-reply@uwdata.ca';
$subject = $subject;
$message = $content;
if (!IN_PRODUCTION) {
echo $content;
}
$recipients = new Swift_RecipientList();
$recipients->addTo($email);
// Build the HTML message
$message = new Swift_Message($subject, $message, "text/html");
$succeeded = !!$swift->send($message, $recipients, $from);
$swift->disconnect();
return $succeeded;
}
示例6: send_email
private function send_email($result)
{
// Create new password for customer
$new_pass = text::random('numeric', 8);
if (isset($result->member_email) && !empty($result->member_email)) {
$result->member_pw = md5($new_pass);
}
$result->save();
//Use connect() method to load Swiftmailer
$swift = email::connect();
//From, subject
//$from = array($this->site['site_email'], 'Yesnotebook get password');
$from = $this->site['site_email'];
$subject = 'Your Temporary Password for ' . $this->site['site_name'];
//HTML message
//print_r($html_content);die();
//Replate content
$html_content = $this->Data_template_Model->get_value('EMAIL_FORGOTPASS');
$name = $result->member_fname . ' ' . $result->member_lname;
$html_content = str_replace('#name#', $name, $html_content);
if (isset($result->member_email) && !empty($result->member_email)) {
$html_content = str_replace('#username#', $result->member_email, $html_content);
}
$html_content = str_replace('#site#', substr(url::base(), 0, -1), $html_content);
$html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
$html_content = str_replace('#password#', $new_pass, $html_content);
$html_content = str_replace('#EmailAddress#', $this->site['site_email'], $html_content);
//fwrite($fi, $html_content);
//Build recipient lists
$recipients = new Swift_RecipientList();
if (isset($result->member_email) && !empty($result->member_email)) {
$recipients->addTo($result->member_email);
}
//Build the HTML message
$message = new Swift_Message($subject, $html_content, "text/html");
if ($swift->send($message, $recipients, $from)) {
//$this->session->set_flash('success_msg',Kohana::lang('errormsg_lang.info_mail_change_pass'));
if (isset($result->member_email) && !empty($result->member_email)) {
url::redirect(url::base() . 'forgotpass/thanks/' . $result->uid . '/customer');
}
die;
} else {
}
// Disconnect
$swift->disconnect();
}
示例7: send_email
private function send_email($record, $member, $test)
{
$swift = email::connect();
$from = $this->site['site_email'];
$mailuser = $this->sess_cus['email'];
$subject = 'Check Code ' . $this->site['site_name'];
$html_content = $this->data_template_model->get_value('EMAIL_CHECKCODE_USER');
$html_content = str_replace('#date#', date('m/y/Y', strtotime('now')), $html_content);
$html_content = str_replace('#username#', $this->sess_cus['name'], $html_content);
$html_content = str_replace('#test#', $test['test_title'], $html_content);
$html_content = str_replace('#description#', $record['description'] != '' ? '<p><strong>Description: ' . $record['description'] . '</strong></p>' : '', $html_content);
$html_content = str_replace('#period#', isset($list['start_date']) && $record['start_date'] != 0 ? date('m/d/Y', $record['start_date']) : '' . (isset($list['end_date']) && $record['end_date'] != 0) ? ' ~ ' . date('m/d/Y', $record['end_date']) : 'No limit', $html_content);
$html_content = str_replace('#no#', isset($record['qty']) ? $record['usage_qty'] + 1 . '/' . $record['qty'] : 'No limit', $html_content);
$recipients = new Swift_RecipientList();
$recipients->addTo($this->site['site_email']);
$recipients->addTo($mailuser);
if (isset($record['email']) && $record['email'] != '') {
$recipients->addTo($record['email']);
}
$message = new Swift_Message($subject, $html_content, "text/html");
if ($swift->send($message, $recipients, $from)) {
} else {
}
// Disconnect
$swift->disconnect();
}
示例8: send
public static function send($to, $from, $subject, $message, $html = false)
{
// Connect to SwiftMailer
Email::$mail === NULL and email::connect();
// Determine the message type
$html = $html === true ? 'text/html' : 'text/plain';
// Create the message
if (self::$view) {
$template = self::$view;
} else {
$config = kohana::$config->load('email');
$template = View::factory($config['template']);
$template->set('message', $message);
}
$message .= $template->render();
$message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
if (is_string($to)) {
// Single recipient
$message->setTo($to);
} elseif (is_array($to)) {
if (isset($to[0]) and isset($to[1])) {
// Create To: address set
$to = array('to' => $to);
}
foreach ($to as $method => $set) {
if (!in_array($method, array('to', 'cc', 'bcc'), true)) {
// Use To: by default
$method = 'to';
}
// Create method name
$method = 'add' . ucfirst($method);
if (is_array($set)) {
// Add a recipient with name
$message->{$method}($set[0], $set[1]);
} else {
// Add a recipient without name
$message->{$method}($set);
}
}
}
if (is_string($from)) {
// From without a name
$message->setFrom($from);
} elseif (is_array($from)) {
// From with a name
$message->setFrom($from[0], $from[1]);
}
return Email::$mail->send($message);
}
示例9: send_email
private function send_email($record)
{
//Use connect() method to load Swiftmailer
$swift = email::connect();
//From, subject
$from = $this->site['site_email'];
$subject = 'Testing ' . $this->site['site_name'];
//HTML message
$html_content = Data_template_Model::get_value('EMAIL_TESTING');
//Replate content
if (isset($this->sess_cus['name']) && !empty($this->sess_cus['name'])) {
$name = $this->sess_cus['name'];
} else {
$name = $this->sess_cus['email'];
}
$html_content = str_replace('#name#', $name, $html_content);
$test = $this->test_model->get($record['test_uid']);
$html_content = str_replace('#test#', $test['test_title'], $html_content);
$html_content = str_replace('#date#', $this->format_int_date($record['testing_date'], $this->site['site_short_date']), $html_content);
$html_content = str_replace('#score#', $record['testing_score'], $html_content);
$html_content = str_replace('#duration#', gmdate("H:i:s", $record['duration']), $html_content);
$html_content = str_replace('#code#', $record['testing_code'], $html_content);
$html_content = str_replace('#site#', $this->site['site_name'], $html_content);
//Build recipient lists
$recipients = new Swift_RecipientList();
$recipients->addTo($this->sess_cus['email']);
//$recipients->addTo($this->site['site_email']);
//Build the HTML message
$message = new Swift_Message($subject, $html_content, "text/html");
if ($swift->send($message, $recipients, $from)) {
} else {
}
// Disconnect
$swift->disconnect();
}
示例10: send
/**
* Send an email message.
*
* @param string|array recipient email (and name), or an array of To, Cc, Bcc names
* @param string|array sender email (and name)
* @param string message subject
* @param string message body
* @param boolean send email as HTML
* @return integer number of emails sent
*/
public static function send($to, $from, $subject, $message, $html = FALSE, $header = array())
{
// Connect to SwiftMailer
Email::$mail === NULL and email::connect();
// Determine the message type
$html = $html === TRUE ? 'text/html' : 'text/plain';
// Create the message
$message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
if (is_string($to)) {
// Single recipient
$message->setTo($to);
} elseif (is_array($to)) {
if (isset($to[0]) and isset($to[1])) {
// Create To: address set
$to = array('to' => $to);
}
foreach ($to as $method => $set) {
if (!in_array($method, array('to', 'cc', 'bcc'))) {
// Use To: by default
$method = 'to';
}
// Create method name
$method = 'add' . ucfirst($method);
if (is_array($set)) {
// Add a recipient with name
// If set is something like a
// 'cc' => array( array( 'person1@example.org', 'person2@otherdomain.org' => 'Person 2 Name', 'person3@example.org' ) );
if (count($set) == 1 && is_array($set[0])) {
foreach ($set[0] as $value) {
if (is_array($value)) {
// Add a recipient with name
$message->{$method}($value[0], $value[1]);
} else {
// Add a recipient without name
$message->{$method}($value);
}
}
} else {
$message->{$method}($set[0], $set[1]);
}
} else {
// Add a recipient without name
$message->{$method}($set);
}
}
}
if (is_string($from)) {
// From without a name
$message->setFrom($from);
} elseif (is_array($from)) {
// From with a name
$message->setFrom($from[0], $from[1]);
}
// Apply additional headers, like a List-Unsubscribe: <http://domain.com/member/unsubscribe/?listname=espc-tech@domain.com?id=12345N>
// Header format is array('List-Unsubscribe'=>'<http://domain.com/member/unsubscribe/?listname=espc-tech@domain.com?id=12345N>')
if (count($header)) {
$headers = $message->getHeaders();
foreach ($header as $name => $value) {
$headers->addTextHeader($name, $value);
}
}
return Email::$mail->send($message);
}
示例11: send_multipart
/**
* Send an email message.
*
* @param string|array recipient email (and name), or an array of To, Cc, Bcc names
* @param string|array sender email (and name)
* @param string message subject
* @param string message body
* @param boolean send email as HTML
* @return integer number of emails sent
*/
public static function send_multipart($to, $from, $subject, $plain = '', $html = '', $attachments = array())
{
// Connect to SwiftMailer
email::$mail === NULL and email::connect();
// Create the message
$message = Swift_Message::newInstance($subject);
// Add some "parts"
switch (true) {
case strlen($html) and strlen($plain):
$message->setBody($html, 'text/html');
$message->addPart($plain, 'text/plain');
break;
case strlen($html):
$message->setBody($html, 'text/html');
break;
case strlen($plain):
$message->setBody($plain, 'text/plain');
break;
default:
$message->setBody('', 'text/plain');
}
if (!empty($attachments)) {
foreach ($attachments as $file => $mime) {
$filename = basename($file);
// Use the Swift_File class
$message->attach(Swift_Attachment::fromPath($file)->setFilename($filename));
}
}
if (is_string($to)) {
// Single recipient
$recipients = $message->setTo($to);
} elseif (is_array($to)) {
if (isset($to[0]) and isset($to[1])) {
// Create To: address set
$to = array('to' => $to);
}
foreach ($to as $method => $set) {
if (!in_array($method, array('to', 'cc', 'bcc'))) {
// Use To: by default
$method = 'to';
}
// Create method name
$method = 'add' . ucfirst($method);
if (is_array($set)) {
// Add a recipient with name
$message->{$method}($set[0], $set[1]);
} else {
// Add a recipient without name
$message->{$method}($set);
}
}
}
if (is_string($from)) {
// From without a name
$from = $message->setFrom($from);
} elseif (is_array($from)) {
// From with a name
$from = $message->setFrom(array($from[0] => $from[1]));
}
return email::$mail->send($message);
}
示例12: send_out_user_email
function send_out_user_email($db, $emailContent, $userId, $notificationIds, $email_config, $subscriptionSettingsPageUrl)
{
$emailContent .= '<a href="' . $subscriptionSettingsPageUrl . '?user_id=' . $userId . '&warehouse_url=' . url::base() . '">Click here to update your subscription settings.</a><br/><br/>';
$cc = null;
$swift = email::connect();
// Use a transaction to allow us to prevent the email sending and marking of notification as done
// getting out of step
try {
//Get the user's email address from the people table
$userResults = $db->select('people.email_address')->from('people')->join('users', 'users.person_id', 'people.id')->where('users.id', $userId)->limit(1)->get();
$defaultEmailSubject = 'You have new notifications.';
try {
$emailSubject = kohana::config('notification_emails.email_subject');
//Handle config file not present
} catch (Exception $e) {
$emailSubject = $defaultEmailSubject;
}
if (empty($emailSubject)) {
$emailSubject = $defaultEmailSubject;
}
//When configured, add a link on the email to the notifications page
try {
$notificationsLinkUrl = kohana::config('notification_emails.notifications_page_url');
} catch (exception $e) {
}
if (!empty($notificationsLinkUrl)) {
try {
$notificationsLinkText = kohana::config('notification_emails.notifications_page_url_text');
} catch (exception $e) {
}
if (empty($notificationsLinkText)) {
$notificationsLinkText = 'Click here to go your notifications page.';
}
$emailContent .= '<a href="' . $notificationsLinkUrl . '">' . $notificationsLinkText . '</a></br>';
}
$message = new Swift_Message($emailSubject, $emailContent, 'text/html');
$recipients = new Swift_RecipientList();
$recipients->addTo($userResults[0]->email_address);
// send the email
$swift->send($message, $recipients, $email_config['address']);
kohana::log('info', 'Email notification sent to ' . $userResults[0]->email_address);
//All notifications that have been sent out in an email are marked so we don't resend them
$db->set('email_sent', 'true')->from('notifications')->in('id', $notificationIds)->update();
//As Verifier Tasks, Pending Record Tasks need to be actioned, we don't auto acknowledge them
$db->set('acknowledged', 't')->from('notifications')->where("source_type != 'VT' AND source_type != 'PT'")->in('id', $notificationIds)->update();
} catch (Exception $e) {
$db->rollback();
throw $e;
}
}
示例13: send_email
private function send_email($record)
{
//Use connect() method to load Swiftmailer
$swift = email::connect();
//From, subject
$from = $record['txt_email'];
$subject = Kohana::lang('contact_lang.tt_page') . ' ' . $this->site['site_name'];
//HTML message
$html_content = Data_template_Model::get_value('EMAIL_CONTACT', $this->get_client_lang());
//Replate content
$record['txt_content'] = isset($record['txt_content']) ? str_replace(array("\r\n", "\r", "\n"), "<br/>", $record['txt_content']) : '';
$html_content = str_replace('#contact_name#', $record['txt_name'], $html_content);
$html_content = str_replace('#contact_phone#', $record['txt_phone'], $html_content);
$html_content = str_replace('#contact_subject#', $record['txt_subject'], $html_content);
$html_content = str_replace('#contact_content#', $record['txt_content'], $html_content);
//Build recipient lists
$recipients = new Swift_RecipientList();
$recipients->addTo($this->site['site_email']);
//Build the HTML message
$message = new Swift_Message($subject, $html_content, "text/html");
if ($swift->send($message, $recipients, $from)) {
url::redirect('contact/thanks');
die;
}
//Disconnect
$swift->disconnect();
}
示例14: send_email
private function send_email($result)
{
//Use connect() method to load Swiftmailer
$swift = email::connect();
//From, subject
$pass_random = rand(1000, 9999);
$from = $this->site['site_email'];
$subject = Kohana::lang('login_lang.lbl_forgotpass') . ' ' . $this->site['site_name'];
//HTML message
$html_content = Data_template_Model::get_value('EMAIL_FORGOTPASS', $this->get_admin_lang());
//Replate content
$html_content = str_replace('#name#', $result->user_name, $html_content);
$html_content = str_replace('#username#', $result->user_name, $html_content);
$html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
$html_content = str_replace('#password#', $pass_random, $html_content);
//Build recipient lists
$recipients = new Swift_RecipientList();
$recipients->addTo($result->user_email);
//Build the HTML message
$message = new Swift_Message($subject, $html_content, "text/html");
if ($swift->send($message, $recipients, $from)) {
$this->session->set_flash('success_msg', Kohana::lang('errormsg_lang.info_mail_change_pass'));
$result->user_pass = md5($pass_random);
$result->save();
}
//Disconnect
$swift->disconnect();
}
示例15: config_email_save
/**
* Save the results of a configuration of emails form, unless the skip button was clicked
* in which case the user is redirected to a page allowing them to confirm this.
*/
public function config_email_save()
{
if (isset($_POST['skip'])) {
url::redirect('setup_check/skip_email');
} else {
$source = dirname(dirname(__FILE__)) . '/config_files/_email.php';
$dest = dirname(dirname(dirname(dirname(__FILE__)))) . "/application/config/email.php";
try {
unlink($dest);
} catch (Exception $e) {
// file doesn't exist?'
}
try {
$_source_content = file_get_contents($source);
// Now save the POST form values into the config file
foreach ($_POST as $field => $value) {
$_source_content = str_replace("*{$field}*", $value, $_source_content);
}
file_put_contents($dest, $_source_content);
// Test the email config
$swift = email::connect();
$message = new Swift_Message('Setup test', Kohana::lang('setup.test_email_title'), 'text/html');
$recipients = new Swift_RecipientList();
$recipients->addTo($_POST['test_email']);
if ($swift->send($message, $recipients, $_POST['address']) == 1) {
$_source_content = str_replace("*test_result*", 'pass', $_source_content);
file_put_contents($dest, $_source_content);
url::redirect('setup_check');
} else {
$this->error = Kohana::lang('setup.test_email_failed');
$this->config_email();
}
} catch (Exception $e) {
// Swift mailer messages tend to have the error message as the last part, with each part colon separated.
$msg = explode(':', $e->getMessage());
$this->error = $msg[count($msg) - 1];
kohana::log('error', $e->getMessage());
$this->config_email();
}
}
}