本文整理汇总了PHP中Swift::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift::send方法的具体用法?PHP Swift::send怎么用?PHP Swift::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift
的用法示例。
在下文中一共展示了Swift::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute($arguments = array(), $options = array())
{
// add code here
$databaseManager = new sfDatabaseManager($this->configuration);
$databaseManager->initialize($this->configuration);
$minutes = $options['minutes'];
$time_date_to_check = date('Y-m-d H:i:s', time() - 60 * $minutes);
$mods = LsDoctrineQuery::create()->select('m.user_id,count(m.id)')->from('Modification m')->where('m.created_at > ? and m.user_id > ?', array($time_date_to_check, 2))->groupBy('m.user_id')->execute();
$message_arr = array('spikes' => array(), 'new' => array());
$new_users = array();
$spike_users = array();
foreach ($mods as $mod) {
$previous_mods_count = LsDoctrineQuery::create()->select('m.id')->from('Modification m')->where('m.created_at < ? and m.user_id = ?', array($time_date_to_check, $mod->user_id))->count();
if ($previous_mods_count == 0) {
$user = Doctrine::getTable('sfGuardUser')->find($mod->user_id);
$new_users[] = $user->username . '(' . $mod->count . ')';
$message_arr['new'][] = $user->Profile->public_name . " / " . $user->username . " / " . 'http://littlesis.org/user/modifications?id=' . $user->id . "\n\t{$mod->count} modifications in last {$minutes}";
} else {
if ($mod->count > $previous_mods_count * 0.1) {
$user = Doctrine::getTable('sfGuardUser')->find($mod->user_id);
$spike_users[] = $user->username . '(' . $mod->count . ')';
$message_arr['spikes'][] = $user->Profile->public_name . " / " . $user->username . " / " . 'http://littlesis.org/user/modifications?id=' . $user->id . "\n\t{$mod->count} modifications in last {$minutes} minutes vs. previous count of {$previous_mods_count} modifications";
}
}
}
$message = '';
if (count($message_arr['new'])) {
$message = "New editing:\n\n";
$message .= implode("\n\n", $message_arr['new']);
}
if (count($message_arr['spikes'])) {
if (strlen($message)) {
$message .= "\n\n";
}
$message .= "Spike in editing:\n\n";
$message .= implode("\n\n", $message_arr['spikes']);
}
$short = "n:" . implode("/", $new_users) . "|s:" . implode("/", $spike_users);
if (strlen($message)) {
$subject = count($message_arr['spikes']) . ' spikes & ' . count($message_arr['new']) . ' new -- ' . date('m-d H:i', time());
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message($subject, $message, 'text/plain');
$short = new Swift_Message('', $short, 'text/plain');
$address = new Swift_Address(sfConfig::get('app_mail_contact_sender_address'), sfConfig::get('app_mail_contact_sender_name'));
$mailer->send($message, sfConfig::get('app_mail_contact_recipient_address'), $address);
$mailer->send($short, '7189160925@txt.att.net', $address);
$mailer->send($short, '6464682400@txt.att.net', $address);
$mailer->disconnect();
}
}
示例2: sendMail
public static function sendMail($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
{
include INSTALL_PATH . '/../tools/swift/Swift.php';
include INSTALL_PATH . '/../tools/swift/Swift/Connection/SMTP.php';
include INSTALL_PATH . '/../tools/swift/Swift/Connection/NativeMail.php';
$swift = NULL;
$result = NULL;
try {
if ($smtpChecked) {
$smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, $smtpEncryption == "off" ? Swift_Connection_SMTP::ENC_OFF : ($smtpEncryption == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
$smtp->setUsername($smtpLogin);
$smtp->setpassword($smtpPassword);
$smtp->setTimeout(5);
$swift = new Swift($smtp);
} else {
$swift = new Swift(new Swift_Connection_NativeMail());
}
$message = new Swift_Message($subject, $content, $type);
if ($swift->send($message, $to, $from)) {
$result = true;
} else {
$result = 999;
}
$swift->disconnect();
} catch (Swift_Connection_Exception $e) {
$result = $e->getCode();
} catch (Swift_Message_MimeException $e) {
$result = $e->getCode();
}
return $result;
}
示例3: send
public function send()
{
//load swift class.
require_once CLASSES_DIR . "Swift.php";
Swift_ClassLoader::load("Swift_Connection_SMTP");
// Create the message, and set the message subject.
$message =& new Swift_Message($this->get('subject'));
//create the html / text body
$message->attach(new Swift_Message_Part($this->get('html_body'), "text/html"));
$message->attach(new Swift_Message_Part($this->get('text_body'), "text/plain"));
// Set the from address/name.
$from =& new Swift_Address(EMAIL_USERNAME, EMAIL_NAME);
// Create the recipient list.
$recipients =& new Swift_RecipientList();
// Add the recipient
$recipients->addTo($this->get('to_email'), $this->get('to_name'));
//connect and create mailer
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername(EMAIL_USERNAME);
$smtp->setPassword(EMAIL_PASSWORD);
$mailer = new Swift($smtp);
// Attempt to send the email.
try {
$result = $mailer->send($message, $recipients, $from);
$mailer->disconnect();
$this->set('status', 'sent');
$this->set('sent_date', date("Y-m-d H:i:s"));
$this->save();
return true;
} catch (Swift_BadResponseException $e) {
return $e->getMessage();
}
}
示例4: email
/**
*
* @param $sender
* @param $senderPass
* @param $receiver
* @param $subject
* @param $message
* @return unknown_type
*/
public function email($sender, $senderPass, $receiver, $subject, $message, $replyTo = 'no-reply@exambuff.co.uk')
{
try {
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_SSL);
$smtp->setTimeout(10);
$smtp->setUsername($sender);
$smtp->setPassword($senderPass);
$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift = new Swift($smtp, 'exambuff.co.uk');
} catch (Exception $e) {
$error = $e->getMessage();
}
$msgSubject = $subject;
$msgBody = $message;
$swfMessage = new Swift_Message($msgSubject, $msgBody);
try {
$swift->send($swfMessage, $receiver, $replyTo);
return true;
} catch (Exception $e) {
if (!@$error) {
$error = '';
}
$error .= $e->getMessage();
log_message('error', $error);
}
return @$error;
}
示例5: send
/**
* Send an email to a number of recipients
* Returns the number of successful recipients, or FALSE on failure
* @param mixed The recipients to send to. One of string, array, 2-dimensional array or Swift_Address
* @param mixed The address to send from. string or Swift_Address
* @param string The message subject
* @param string The message body, optional
* @return int
*/
function send($recipients, $from, $subject, $body = null)
{
$this->addTo($recipients);
$sender = false;
if (is_string($from)) {
$sender = $this->stringToAddress($from);
} elseif (is_a($from, "Swift_Address")) {
$sender =& $from;
}
if (!$sender) {
return false;
}
$this->message->setSubject($subject);
if ($body) {
$this->message->setBody($body);
}
$sent = 0;
Swift_Errors::expect($e, "Swift_ConnectionException");
if (!$this->exactCopy && !$this->recipients->getCc() && !$this->recipients->getBcc()) {
$sent = $this->swift->batchSend($this->message, $this->recipients, $sender);
} else {
$sent = $this->swift->send($this->message, $this->recipients, $sender);
}
if (!$e) {
Swift_Errors::clear("Swift_ConnectionException");
if ($this->autoFlush) {
$this->flush();
}
return $sent;
}
$this->setError("Sending failed:<br />" . $e->getMessage());
return false;
}
示例6: executePassword
public function executePassword()
{
$this->form = new RequestPasswordForm();
if ($this->getRequest()->isMethod('get')) {
return;
}
$this->form->bind($this->getRequest()->getParameter('form'));
if (!$this->form->isValid()) {
return;
}
$email = $this->form->getValue('email');
$password = substr(md5(rand(100000, 999999)), 0, 6);
$sfGuardUserProfile = sfGuardUserProfilePeer::retrieveByEmail($email);
$sfGuardUser = $sfGuardUserProfile->getSfGuardUser();
$sfGuardUser->setPassword($password);
try {
$connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
$connection->setUsername('umut.utkan@sistemas.com.tr');
$connection->setPassword('gahve123');
$mailer = new Swift($connection);
$message = new Swift_Message('Request Password');
$mailContext = array('email' => $email, 'password' => $password, 'username' => $sfGuardUser->getUsername(), 'full_name' => $sfGuardUserProfile->getFirstName());
$message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordHtmlBody', $mailContext), 'text/html'));
$message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordTextBody', $mailContext), 'text/plain'));
$mailer->send($message, $email, 'admin@project-y.com');
$mailer->disconnect();
} catch (Exception $e) {
$mailer->disconnect();
}
$sfGuardUser->save();
$this->getUser()->setFlash('info', 'A new password is sent to your email.');
$this->forward('site', 'message');
}
示例7: send
/**
* Send a mail
*
* @param string $subject
* @param string $content
* @return bool|string false is everything was fine, or error string
*/
public function send($subject, $content)
{
try {
// Test with custom SMTP connection
if ($this->smtp_checked) {
$smtp = new Swift_Connection_SMTP($this->server, $this->port, $this->encryption == "off" ? Swift_Connection_SMTP::ENC_OFF : ($this->encryption == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
$smtp->setUsername($this->login);
$smtp->setpassword($this->password);
$smtp->setTimeout(5);
$swift = new Swift($smtp);
} else {
// Test with normal PHP mail() call
$swift = new Swift(new Swift_Connection_NativeMail());
}
$message = new Swift_Message($subject, $content, 'text/html');
if (@$swift->send($message, $this->email, 'no-reply@' . Tools::getHttpHost(false, false, true))) {
$result = false;
} else {
$result = 'Could not send message';
}
$swift->disconnect();
} catch (Swift_Exception $e) {
$result = $e->getMessage();
}
return $result;
}
示例8: swiftIt
public function swiftIt($subject, $msg)
{
if (empty($subject) || empty($msg)) {
return false;
}
$email = $this->toEmail;
$ret = false;
if (self::emailIsValid($this->toEmail)) {
$name = $this->toName;
$from = $this->fromEmail;
$fromName = $this->fromName;
try {
//Start Swift
$swift = new Swift(new Swift_Connection_SMTP(defined('SMTP_SERVER') ? SMTP_SERVER : '127.0.0.1:25'));
//Create the message
$message = new Swift_Message($subject, $msg);
//customize names
$to = new Swift_Address($email, $name);
$from = new Swift_Address($from, $fromName);
//Now check if Swift actually sends it
if ($swift->send($message, $to, $from)) {
$log = "sent mail to: {$to}\n";
$ret = true;
}
} catch (Swift_ConnectionException $e) {
$log = "There was a problem communicating with SMTP: " . $e->getMessage() . "\n";
} catch (Swift_Message_MimeException $e) {
$log = "There was an unexpected problem building the email:" . $e->getMessage() . "\n";
}
}
return $ret;
}
示例9: send
/**
* Send an email to a number of recipients
* Returns the number of successful recipients, or FALSE on failure
* @param mixed The recipients to send to. One of string, array, 2-dimensional array or Swift_Address
* @param mixed The address to send from. string or Swift_Address
* @param string The message subject
* @param string The message body, optional
* @return int
*/
public function send($recipients, $from, $subject, $body = null)
{
$this->addTo($recipients);
$sender = false;
if (is_string($from)) {
$sender = $this->stringToAddress($from);
} elseif ($from instanceof Swift_Address) {
$sender = $from;
}
if (!$sender) {
return false;
}
$this->message->setSubject($subject);
if ($body) {
$this->message->setBody($body);
}
try {
if (!$this->exactCopy && !$this->recipients->getCc() && !$this->recipients->getBcc()) {
$sent = $this->swift->batchSend($this->message, $this->recipients, $sender);
} else {
$sent = $this->swift->send($this->message, $this->recipients, $sender);
}
if ($this->autoFlush) {
$this->flush();
}
return $sent;
} catch (Swift_ConnectionException $e) {
$this->setError("Sending failed:<br />" . $e->getMessage());
return false;
}
}
示例10: send
/**
* Send a contact mail (text only) with the data provided by the given form.
*
* @uses Swift
*
* @throws InvalidArgumentException
* @throws RuntimeException
*
* @param sfContactForm $form A valid contact form which contains the content.
* @param sfContactFormDecorator $decorator Defaults to null. If given, the decorated subject and message will be used.
*
* @return bool True if all recipients got the mail.
*/
public static function send(sfContactForm $form, sfContactFormDecorator $decorator = null)
{
if (!$form->isValid()) {
throw new InvalidArgumentException('The given form is not valid.', 1);
}
if (!class_exists('Swift')) {
throw new RuntimeException('Swift could not be found.');
}
// set up sender
$from = sfConfig::get('sf_contactformplugin_from', false);
if ($from === false) {
throw new InvalidArgumentException('Configuration value of sf_contactformplugin_from is missing.', 2);
}
// where to send the contents of the contact form
$mail = sfConfig::get('sf_contactformplugin_mail', false);
if ($mail === false) {
throw new InvalidArgumentException('Configuration value of sf_contactformplugin_mail is missing.', 3);
}
// set up mail content
if (!is_null($decorator)) {
$subject = $decorator->getSubject();
$body = $decorator->getMessage();
} else {
$subject = $form->getValue('subject');
$body = $form->getValue('message');
}
// set up recipients
$recipients = new Swift_RecipientList();
// check amount for given recipients
$recipientCheck = 0;
// use the sender as recipient to apply other recipients only as blind carbon copy
$recipients->addTo($from);
$recipientCheck++;
// add a mail where to send the message
$recipients->addBcc($mail);
$recipientCheck++;
// add sender to recipients, if chosen
if ($form->getValue('sendcopy')) {
$recipients->addBcc($form->getValue('email'));
$recipientCheck++;
}
if (count($recipients->getIterator('bcc')) === 0) {
throw new InvalidArgumentException('There are no recipients given.', 4);
}
// send the mail using swift
try {
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message($subject, $body, 'text/plain');
$countRecipients = $mailer->send($message, $recipients, $from);
$mailer->disconnect();
return $countRecipients == $recipientCheck;
} catch (Exception $e) {
$mailer->disconnect();
throw $e;
}
}
示例11: testWaitingTimeIsHonoured
/**
* Tests that the sleep() time is used if it's set.
*/
public function testWaitingTimeIsHonoured()
{
$conn = $this->getWorkingMockConnection(20, null, 5);
$swift = new Swift($conn);
$plugin = new MockAntiFloodPlugin();
$plugin->setWait(10);
$plugin->setThreshold(5);
$plugin->expect("wait", array(10));
$swift->attachPlugin($plugin, "antiflood");
for ($i = 0; $i < 20; $i++) {
$swift->send(new Swift_Message("foo", "bar"), new Swift_Address("foo@bar.com"), new Swift_Address("foo@bar.com"));
}
}
示例12: executeRegister
public function executeRegister($request)
{
$userParams = $request->getParameter('api_user');
$this->user_form = new ApiUserForm();
$this->created = false;
if ($request->isMethod('post')) {
//bind request params to form
$captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'));
$userParams = array_merge($userParams, array('captcha' => $captcha));
$this->user_form->bind($userParams);
//look for user with duplicate email
$q = LsDoctrineQuery::create()->from('ApiUser u')->where('u.email = ?', $userParams['email']);
if ($q->count()) {
$validator = new sfValidatorString(array(), array('invalid' => 'There is already an API user with that email address.'));
$this->user_form->getErrorSchema()->addError(new sfValidatorError($validator, 'invalid'), 'email');
$request->setError('email', 'There is already a user with that email');
}
if ($this->user_form->isValid() && !$request->hasErrors()) {
//create inactive api user
$user = new ApiUser();
$user->name_first = $userParams['name_first'];
$user->name_last = $userParams['name_last'];
$user->email = $userParams['email'];
$user->reason = $userParams['reason'];
$user->api_key = $user->generateKey();
$user->is_active = 1;
$user->save();
//add admin notification email to queue
$email = new ScheduledEmail();
$email->from_name = sfConfig::get('app_mail_sender_name');
$email->from_email = sfConfig::get('app_mail_sender_address');
$email->to_name = sfConfig::get('app_mail_sender_name');
$email->to_email = sfConfig::get('app_mail_sender_address');
$email->subject = sprintf("%s (%s) has requested an API key", $user->getFullName(), $user->email);
$email->body_text = $this->getPartial('keyrequestnotify', array('user' => $user));
$email->save();
$this->created = true;
//send approval email
$mailBody = $this->getPartial('keycreatenotify', array('user' => $user));
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message('Your LittleSis API key', $mailBody, 'text/plain');
$from = new Swift_Address(sfConfig::get('app_mail_sender_address'), sfConfig::get('app_mail_sender_name'));
$recipients = new Swift_RecipientList();
$recipients->addTo($user->email, $user->name_first . ' ' . $user->name_last);
$recipients->addBcc(sfConfig::get('app_mail_sender_address'));
$mailer->send($message, $recipients, $from);
$mailer->disconnect();
}
}
}
示例13: testThresholdIsHonouredBeforeRotating
/**
* Test that the number of emails (threshold) can be set.
*/
public function testThresholdIsHonouredBeforeRotating()
{
$plugin = new Swift_Plugin_ConnectionRotator();
$conn = $this->getWorkingMockConnection(20, new MockRotatorConnection(), 6, 2);
$conn->expectCallCount("nextConnection", 3);
$conn->setReturnValueAt(0, "getActive", 0);
$conn->setReturnValueAt(1, "getActive", 1);
$conn->setReturnValueAt(2, "getActive", 2);
$swift = new Swift($conn);
$swift->attachPlugin(new Swift_Plugin_ConnectionRotator(6), "foo");
for ($i = 0; $i < 20; $i++) {
$swift->send(new Swift_Message("subject", "body"), new Swift_Address("foo@bar.tld"), new Swift_Address("zip@button.com"));
}
}
示例14: sendActivationMail
/**
* Send an email with an activation link to verify the subscriber is the owner of the email address.
*
* @throws InvalidArgumentException
* @throws Exception
*
* @return bool
*/
protected function sendActivationMail(Subscriber $subscriber)
{
try {
$from = sfNewsletterPluginConfiguration::getFromEmail();
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message(sfConfig::get('sf_newsletter_plugin_activation_mail_subject', 'Newsletter Subscription'), $this->getPartial('activation_mail', array('subscriber' => $subscriber)), 'text/html');
$sent = $mailer->send($message, $subscriber->getEmail(), $from);
$mailer->disconnect();
return $sent === 1;
} catch (Exception $e) {
if (!empty($mailer)) {
$mailer->disconnect();
}
throw $e;
}
}
示例15: sendEmail
static function sendEmail($params)
{
$mailTo = $params['to'];
$mailFrom = $params['from'];
try {
// Create the Mail Object
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message($params['subject'], $params['body'], 'text/html');
// Send
$mailer->send($message, $mailTo, $mailFrom);
$mailer->disconnect();
// echo 'Email Sent';
} catch (Exception $e) {
$mailer->disconnect();
echo 'Error: ' . $e;
}
}