note 41340 added to ref.mail

From: Date: Tue, 06 Apr 2004 21:36:57 +0000
Subject: note 41340 added to ref.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-67734@lists.php.net to get a copy of this message
If your system MTA is exim, you might find using it the following way gives you more control over the message that is sent. It uses batch SMTP rather than the hideous "-t" sendmail-like argument, and as a result allows the envelope and the headers to be specified seperately. // recipient, subject, body, [ [ [ headers ], sender ], helo] // bsmtp("recipient@address.com", "Subject", array("Line 1", "Line 2"), array(), "sender@address.com", "host.address.com); // OR // bsmtp(array("recipient1@address.com", "recipient2@address.com), "Subject", array("Line 1", "Line 2"), array(), "sender@addr$ function bsmtp($recipients, $subject, $body, $headers = array(), $sender= "<>", $helo = "") { $exim = "/usr/local/sbin/exim -bS"; if ( $helo == "" ) { $helo = $_SERVER["HTTP_HOST"]; } if ( ! $headers ) { if (is_array($recipients)) { $c="To: "; foreach ($recipients as $r) { $toheader .= $c . $r; $c = ", "; } } else { $toheader = "To: " . $recipients; } if ( ereg("@", $sender)) { $fromheader = "From: " . $sender; } else { $fromheader = "From: <MAILER-DAEMON@" . $_SERVER["HTTP_HOST"] . ">"; } $subj = "Subject: " . $subject; $headers = array($toheader, $fromheader, $subj); } $headers[] = "X-Mailer: Dave's better php mail function"; print "<PRE>"; $fd = popen($exim, "w"); fputs($fd, "HELO " . $helo . "\n"); fputs($fd, "MAIL FROM: " . $sender . "\n"); if (is_array($recipients)) { foreach ($recipients as $r) { fputs($fd, "RCPT TO: " . $r . "\n"); } } else { fputs($fd, "RCPT TO: " . $recipients . "\n"); } fputs($fd, "DATA\n"); foreach ( $headers as $h ) { fputs($fd, $h . "\n"); } fputs($fd, "\n"); foreach ( $body as $b ) { fputs($fd, $b . "\n"); } fputs($fd, "\n.\nQUIT\n"); sleep(1); pclose($fd); } } ---- Manual Page -- http://www.php.net/manual/en/ref.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41340 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41340&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41340&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67734) next »