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. Otherwise, you’ll be enabling web spam.
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('firstname.lastname@example.org', 'email@example.com');
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().
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();
If you have an array of paragraphs to add, you can use $message->paragraphs() to add them.
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('firstname.lastname@example.org'); … $morerecipients = array('email@example.com', 'firstname.lastname@example.org'); $queue->recipient($morerecipients);
The system checks to make sure that your sender is valid. If it isn’t valid, then it won’t use that sender. However, senders are required in order to send a message.
If you can’t trust that your sender is going to be valid, you can set up a default sender:
Always use a known valid address for the default sender. If your default sender fails as well, your messages will not be sent.
If you need to add special headers to your message, use the “headers()” method:
You can also pass an array to the headers method.
Don’t forget that you can use Form Verification to verify form input.
E-mail messages can’t have any line longer than 1,000 characters; most servers will break lines well before that to avoid problems. The plug-in will normally leave your formatting alone, but if any line is longer than 850 characters it will autowrap all text to 75 characters per line.