USD Logo MySanDiego | Libraries | Bookstore | Find People | A to Z Index | Resources | Jobs
 Prospective Students | Current Students | Alumni | Faculty & Employees | Visitors | International
About USDAdmissionsAcademicsNews and EventsAdministrationAthleticsGiving

Mail Queue

Mail Queue

Sometimes you need to have your PHP scripts send e-mails to yourself for notification. This plug-in will help you do it.

Never send e-mails to addresses you’ve collected over web forms! Unless you personally know that this particular address is valid and expects mail from USD, do not send it mail.

If you just want to send e-mail to yourself whenever someone fills out a web form, see Email Form. That plug-in uses this plug-in behind the scenes to automatically send submitted forms to an address you specify. This plug-in is for when you need more control than the automatic plug-in supports.

Queuing a message

The basic script portion is fairly simple:

include_once("/web/includes/mail.phpi"); $message = new EMail($recipients, $subject, $sender, $body); $message->queue();

This will queue up the message, and it will be sent within the next fifteen minutes.

If there is more than one recipient, use an array to set up that variable:

$recipients = array('user1@sandiego.edu', 'user2@sandiego.edu');

If you don’t want to set up a custom $body, and you are using the Form Verification plug-in, you can use $form->allFields() in place of $body. If you’re using the Easy SQL in PHP plug-in, use $sql->form->allFields().

Advanced use

Only the $recipients and $subject parameters are required. You can set up the $sender and $body later in your script.

$message = EMail($recipients, $subject); … $message->paragraph($line1); … $message->paragraph($line2); … $message->sender('youraddress'); $message->queue();

More recipients

While you have to have at least one recipient in mind when you set up the message, you can add more recipients later.

$queue->recipient('user3@sandiego.edu'); … $morerecipients = array('user4@sandiego.edu', 'user5@sandiego.edu'); $queue->recipient($morerecipients);

Special headers

If you need to add special headers to your message, use the “headers()” method:

$message->headers('Reply-To: myalias@sandiego.edu');

You can also pass an array to the headers method.

Form verification

Don’t forget that you can use Form Verification to verify form input.