Trouble using PEAR's Mail_Queue

1.9k views Asked by At

I'm trying to implement PEAR's Mail_Queue package to queue some emails for a web application. I've used the documentation at http://pear.php.net/manual/en/package.mail.mail-queue.mail-queue.tutorial.php to write a small test script.

My problem is that the database is not being updated, and it's not producing errors.

EDIT

// mail_queue db options
$db_options['type'] = 'mdb2';
$db_options['dsn'] = DSN;
$db_options['mail_table'] = 'mail_queue';

// mail_queue sending options
$mail_options['driver'] = 'smtp';
$mail_options['host'] = 'smtp.gmail.com';
$mail_options['port'] = 25;
$mail_options['localhost'] = $host;
$mail_options['auth'] = true;
$mail_options['user'] = MAILUSER;
$mail_options['pass'] = MAILPASS;

require "Queue.php";

$mail_queue =& new Mail_Queue($db_options,$mail_options);

$from = '[email protected]';
$to = '[email protected]';
$message = 'This is a test';

$headers = array('From' => $from,
    'To' => $to,
    'Subject' => 'Someone has sent you an email!');

$mime =& new Mail_mime();
$mime->setTXTBody($message);
$body = $mime->get();

$headers = $mime->headers($headers,true);
print $mail_queue->put($from,$to,$headers,$body);

This produces the error Mail Queue Error: Cannot connect to database . However I checked all of the connection information and it's correct. Also, adding if (PEAR::isError($mail)) die($mail->getMessage()); produces no errors!

1

There are 1 answers

2
xyhhx On BEST ANSWER

OK, I finally have my mail queue file working. Here are the steps I took to get it to function:

1. Enable error messages

To enable error handling, I added this snippet:

function handle_pear_error($e) {
    die($e->getMessage() . ' ' . print_r($e->getUserInfo(), true));
}
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error');

Once I added this, I reloaded the page and I was getting the following error:

Call to undefined function: MDB2_Driver_mysql::_isNewLinkSet()

2. Update MDB2's MySQL driver

I searched that error and found that it's usually a result of either not having an up-to-date MDB2 library or its MySQL driver.

So I updated both and it's working!