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. $to_header = ''; // Add an additional bit of error checking to the To field. $mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to); if (preg_match('#[^ ]+\@[^ ]+#', $mail_to)) { fputs($socket, "RCPT TO: <$mail_to>\r\n"); server_parse($socket, "250", __LINE__); } // 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: $mail_to\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; } ?>