note 41340 modified in ref.mail by didou

From: Date: Sun, 23 Apr 2006 22:25:18 +0000
Subject: note 41340 modified in ref.mail by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-109193@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$ <?php 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); } } ?> --was-- 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$ <?php 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); } } ?> http://php.net/manual/en/ref.mail.php

« previous php.notes (#109193) next »