note 32577 added to ref.mail
| From: | Tomislav at rack1 dot php dot net | Date: | Sun, 01 Jun 2003 04:11:22 +0000 |
| Subject: | note 32577 added to ref.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49512@lists.php.net to get a copy of this message | ||
While working with a system that would send a lot of emails, I wanted to skip the local antivirus
program (Amavis with local relay virus check) so that sending the emails won't load the server
heavily. Also, I needed to change the "Return-path:" header of the message.
This is the solution I came up with:
<?php
$messg = "Here we put the content of the message.";
$sender = "email@example.com";
$sendmail = "/usr/sbin/sendmail -t -f $sender -C /etc/sendmail.orig.cf";
/*
Notice that sendmail is receiving three params:
-t
Scan the To:, Cc:, and Bcc: from the message itself
-f <email address>
Change the envelope (Return-path:) of the message
-C <config path>:
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);
?>
Notice that this script will be called from a cron job as root (sendmail won't let you use a
different config file unless you are root).
----
Manual Page -- http://www.php.net/manual/en/ref.mail.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32577
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32577&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32577&report=yes