Example #1
0
 /**
  * Send an e-mail message, using Drupal variables and default settings.
  *
  * @see http://pear.php.net/package/Mail/docs
  *
  * @param $message
  *   A message array, as described in hook_mail_alter().
  * @return
  *   TRUE if the mail was successfully accepted, otherwise FALSE.
  */
 public function mail(array $message)
 {
     $php_binary = variable_get(CVWOBASE_D7_PHP_BINARY, FALSE);
     // Send asynchronously, and PHP binary path known
     if ($php_binary && variable_get(CVWOBASE_D7_MAIL_SEND_ASYNC, CVWOBASE_D7_MAIL_SEND_ASYNC_DEFAULT)) {
         DrupalQueue::get(CVWOBASE_MAIL_QUEUE)->createItem($message);
         $execstring = $php_binary . ' ' . DRUPAL_ROOT . '/' . drupal_get_path('module', CVWOBASE_MODULE) . '/cvwobase_d7_email_process.php ' . DRUPAL_ROOT;
         cvwobase_exec($execstring);
         return TRUE;
         // Send inline
     } else {
         $error_queue = new MemoryQueue(CVWOBASE_MAIL_ERROR_QUEUE);
         // name irrelevant
         _cvwobase_d7_send_mail($message, $error_queue);
         if ($error_queue->numberOfItems() > 0) {
             while ($error = $error_queue->claimItem()) {
                 drupal_set_message(t('Unable to send message: PEAR Mail reports error "%error"', array('%error' => $error->data)), 'error');
                 $error_queue->deleteItem($item);
             }
             return FALSE;
         }
         return TRUE;
     }
 }
  2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// $Id$
/**
 * @file
 * Script to send the queued emails, called directly from the command prompt.
 * Parameter passed in (from command prompt) should be DRUPAL_ROOT.
 * Should also be in the same directory as cvwobase_d7_constants.php and cvwobase_d7_mail_functions.php
 */
require_once 'cvwobase_d7_constants.php';
require_once 'cvwobase_d7_mail_functions.php';
// check for command line arguments
if ($argc != 2 || defined(DRUPAL_ROOT)) {
    die('Invalid arguments');
}
// Load Drupal up to database and system variables
define('DRUPAL_ROOT', $argv[1]);
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
$mail_queue = DrupalQueue::get(CVWOBASE_MAIL_QUEUE);
$error_queue = DrupalQueue::get(CVWOBASE_MAIL_ERROR_QUEUE);
// iterate between email batches
while ($item = $mail_queue->claimItem()) {
    $message = $item->data;
    $mail_queue->deleteItem($item);
    _cvwobase_d7_send_mail($message, $error_queue);
}