note 31922 deleted from ref.mail by kennyt
| From: | kennyt@php.net | Date: | Sun, 18 Jul 2004 17:40:30 +0000 |
| Subject: | note 31922 deleted from ref.mail by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73537@lists.php.net to get a copy of this message | ||
Note Submitter: grey at greywyvern dot com
----
Here's a function I'm continually working at to send multiple emails while only opening
the socket once (much faster than mail()) while sending a separate email to each address. It also
includes many headers which you can adjust to your liking. Note the comment which explains the
array format for incoming "To:" addresses.
<?php
function socketmail($toArray, $subject, $message) {
// $toArray format --> array("Name1" => "address1", "Name2"
=> "address2", ...)
ini_set(sendmail_from, "myemail@address.com");
$connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr,
30) or die("Could not talk to the sendmail server!");
$rcv = fgets($connect, 1024);
fputs($connect, "HELO {$_SERVER['SERVER_NAME']}\r\n");
$rcv = fgets($connect, 1024);
while (list($toKey, $toValue) = each($toArray)) {
fputs($connect, "MAIL FROM:myemail@address.com\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "RCPT TO:$toValue\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "DATA\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "Subject: $subject\r\n");
fputs($connect, "From: My Name <myemail@address.com>\r\n");
fputs($connect, "To: $toKey <$toValue>\r\n");
fputs($connect, "X-Sender: <myemail@address.com>\r\n");
fputs($connect, "Return-Path: <myemail@address.com>\r\n");
fputs($connect, "Errors-To: <myemail@address.com>\r\n");
fputs($connect, "X-Mailer: PHP\r\n");
fputs($connect, "X-Priority: 3\r\n");
fputs($connect, "Content-Type: text/plain; charset=iso-8859-1\r\n");
fputs($connect, "\r\n");
fputs($connect, stripslashes($message)." \r\n");
fputs($connect, ".\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "RSET\r\n");
$rcv = fgets($connect, 1024);
}
fputs ($connect, "QUIT\r\n");
$rcv = fgets ($connect, 1024);
fclose($connect);
ini_restore(sendmail_from);
}
?>