c733470ddf4e4600970a549206199ec675b343cb
4 ** This contains all the functions needed to send messages through
8 function smtpReadData($smtpConnection) {
9 $read = fgets($smtpConnection, 1024);
13 $data[$counter] = $read;
14 $read = fgets($smtpConnection, 1024);
19 function sendMessage($smtpServerAddress, $smtpPort, $username, $domain, $t, $c, $b, $subject, $body, $version) {
22 $bcc = parseAddrs($b);
23 $body = stripslashes($body);
24 $from = "$username@$domain";
26 echo "<FONT FACE=\"Arial,Helvetica\">";
27 $smtpConnection = fsockopen($smtpServerAddress, $smtpPort, $errorNumber, $errorString);
28 if (!$smtpConnection) {
29 echo "Error connecting to SMTP Server.<br>";
30 echo "$errorNumber : $errorString<br>";
34 $to_list = getLineOfAddrs($to);
35 $cc_list = getLineOfAddrs($cc);
37 /** Lets introduce ourselves */
38 fputs($smtpConnection, "HELO $domain\n");
39 /** Ok, who is sending the message? */
40 fputs($smtpConnection, "MAIL FROM:<$from>\n");
42 /** send who the recipients are */
43 for ($i = 0; $i < count($to); $i++
) {
44 fputs($smtpConnection, "RCPT TO:<$to[$i]>\n");
46 for ($i = 0; $i < count($cc); $i++
) {
47 fputs($smtpConnection, "RCPT TO:<$cc[$i]>\n");
49 for ($i = 0; $i < count($bcc); $i++
) {
50 fputs($smtpConnection, "RCPT TO:<$bcc[$i]>\n");
53 /** Lets start sending the actual message */
54 fputs($smtpConnection, "DATA\n");
55 fputs($smtpConnection, "Subject: $subject\n"); // Subject
56 fputs($smtpConnection, "To: <$to_list>\n"); // Who it's TO
58 fputs($smtpConnection, "Cc: <$cc_list>\n"); // Who the CCs are
60 fputs($smtpConnection, "X-Mailer: SquirrelMail (version $version)\n"); // Identify SquirrelMail
61 fputs($smtpConnection, "Reply-To: $from\n");
62 fputs($smtpConnection, "MIME-Version: 1.0\n");
63 fputs($smtpConnection, "Content-Type: text/plain; charset=us-ascii\n");
65 fputs($smtpConnection, "$body\n"); // send the body of the message
66 fputs($smtpConnection, ".\n"); // end the DATA part
67 fputs($smtpConnection, "QUIT\n"); // log off