1) { $headers = join("\n", $headers); } else { $headers = $headers[0]; } } $headers = chop($headers); // Make sure there are no bare linefeeds in the headers $headers = preg_replace('#(?\r\n"); server_parse($socket, "250", __LINE__); // Specify each user to send to and build to header. @reset($mail_to_array); while(list(, $mail_to_address) = each($mail_to_array)) { // Add an additional bit of error checking to the To field. $mail_to_address = trim($mail_to_address); if (preg_match('#[^ ]+\@[^ ]+#', $mail_to_address)) { fputs($socket, "RCPT TO: $mail_to_address\r\n"); server_parse($socket, "250", __LINE__); } $to_header .= (($to_header !='') ? ', ' : '') . "$mail_to_address"; } // Ok now do the CC and BCC fields... @reset($bcc); while(list(, $bcc_address) = each($bcc)) { // Add an additional bit of error checking to bcc header... $bcc_address = trim($bcc_address); if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) { fputs($socket, "RCPT TO: $bcc_address\r\n"); server_parse($socket, "250", __LINE__); } } @reset($cc); while(list(, $cc_address) = each($cc)) { // Add an additional bit of error checking to cc header $cc_address = trim($cc_address); if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) { fputs($socket, "RCPT TO: $cc_address\r\n"); server_parse($socket, "250", __LINE__); } } // Ok now we tell the server we are ready to start sending data fputs($socket, "DATA\r\n"); // This is the last response code we look for until the end of the message. server_parse($socket, "354", __LINE__); // Send the Subject Line... fputs($socket, "Subject: $subject\r\n"); // Now the To Header. fputs($socket, "To: $to_header\r\n"); // Now any custom headers.... fputs($socket, "$headers\r\n\r\n"); // Ok now we are ready for the message... fputs($socket, "$message\r\n"); // Ok the all the ingredients are mixed in let's cook this puppy... fputs($socket, ".\r\n"); server_parse($socket, "250", __LINE__); // Now tell the server we are done and close the socket... fputs($socket, "QUIT\r\n"); fclose($socket); return TRUE; } ?>