While I was designing a system that needed to send mass-customized emails from PHP, I faced two problems: a) change the envelope address (Return-path: header) and b) (most important) avoid overloading the server when sending the messages because of virus check.
Basically, I wanted to use a different sendmail configuration file from PHP to skip the relay-mail virus check from Amavis.
Please note that this script is to be called by a cron job as root to limit the number of messages sent on a batch; when getting the records from a database and sending the mails it’s quite easy to overload the server and get sendmail to stop accepting messages/connections.
Add the necessary logic to perform any additional checks, get the DB records and customize the content of the message accordingly.
This is the base code that will allow you to use a different sendmail configuration file:
[php]
$messg = “Here we put the content of the message.”;
$sender = “email@example.com”;
$sendmail = “/usr/sbin/sendmail -t -f $sender -C /etc/sendmail.nocheck.cf”;
/*
Notice that sendmail is receiving three params:
-t Scan the To:, Cc:, and Bcc: from the message itself
-f Change the envelope (Return-path:) of the message
-C Use a different configuration file for sendmail, in this case the config file
skips the virus check
*/
$fd = popen($sendmail, “w”);
fputs($fd, “To: recipient@example.com\r\n”);
fputs($fd, “From: \”Sender Name\” <$sender>\r\n”);
fputs($fd, “Subject: Finally\r\n”);
fputs($fd, “X-Mailer: Mailer Name\r\n\r\n”);
fputs($fd, $body);
pclose($fd);
[/php]
Leave a Reply
You must be logged in to post a comment.