Added some error correction on compose_send.php
[squirrelmail.git] / functions / smtp.php
CommitLineData
b8ea4ed6 1<?
2 /** smtp.php
3 **
4 ** This contains all the functions needed to send messages through
5 ** an smtp server.
6 **/
7
8 function smtpReadData($smtpConnection) {
9 $read = fgets($smtpConnection, 1024);
10 $counter = 0;
11 while ($read) {
12 echo $read . "<BR>";
13 $data[$counter] = $read;
14 $read = fgets($smtpConnection, 1024);
15 $counter++;
16 }
17 }
18
40ee9452 19 function sendMessage($smtpServerAddress, $smtpPort, $username, $domain, $t, $c, $b, $subject, $body, $version) {
20 $to = parseAddrs($t);
21 $cc = parseAddrs($c);
22 $bcc = parseAddrs($b);
4f96d941 23 $body = stripslashes($body);
c175e2e4 24 $from = "$username@$domain";
25
b8ea4ed6 26 echo "<FONT FACE=\"Arial,Helvetica\">";
c175e2e4 27 $smtpConnection = fsockopen($smtpServerAddress, $smtpPort, $errorNumber, $errorString);
b8ea4ed6 28 if (!$smtpConnection) {
29 echo "Error connecting to SMTP Server.<br>";
30 echo "$errorNumber : $errorString<br>";
31 exit;
32 }
b8ea4ed6 33
40ee9452 34 $to_list = getLineOfAddrs($to);
35 $cc_list = getLineOfAddrs($cc);
36
37 /** Lets introduce ourselves */
38 fputs($smtpConnection, "HELO $domain\n");
39 /** Ok, who is sending the message? */
c175e2e4 40 fputs($smtpConnection, "MAIL FROM:<$from>\n");
b8ea4ed6 41
40ee9452 42 /** send who the recipients are */
43 for ($i = 0; $i < count($to); $i++) {
44 fputs($smtpConnection, "RCPT TO:<$to[$i]>\n");
45 }
46 for ($i = 0; $i < count($cc); $i++) {
47 fputs($smtpConnection, "RCPT TO:<$cc[$i]>\n");
48 }
49 for ($i = 0; $i < count($bcc); $i++) {
50 fputs($smtpConnection, "RCPT TO:<$bcc[$i]>\n");
51 }
b8ea4ed6 52
40ee9452 53 /** Lets start sending the actual message */
b8ea4ed6 54 fputs($smtpConnection, "DATA\n");
40ee9452 55 fputs($smtpConnection, "Subject: $subject\n"); // Subject
56 fputs($smtpConnection, "To: <$to_list>\n"); // Who it's TO
57 if ($cc_list) {
58 fputs($smtpConnection, "Cc: <$cc_list>\n"); // Who the CCs are
59 }
60 fputs($smtpConnection, "X-Mailer: SquirrelMail (version $version)\n"); // Identify SquirrelMail
61
62 fputs($smtpConnection, "$body\n"); // send the body of the message
63 fputs($smtpConnection, ".\n"); // end the DATA part
64 fputs($smtpConnection, "QUIT\n"); // log off
65
b8ea4ed6 66 echo "</FONT>";
67 }
68?>