updated some sending stuff
[squirrelmail.git] / functions / smtp.php
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
19 function sendMessage($smtpServerAddress, $smtpPort, $to, $subject, $body) {
20 $to = addslashes($to);
21 $body = addslashes($body);
22 $from = "$username@$domain";
23
24 echo "<FONT FACE=\"Arial,Helvetica\">";
25 $smtpConnection = fsockopen($smtpServerAddress, $smtpPort, $errorNumber, $errorString);
26 if (!$smtpConnection) {
27 echo "Error connecting to SMTP Server.<br>";
28 echo "$errorNumber : $errorString<br>";
29 exit;
30 }
31 echo htmlspecialchars(fgets($smtpConnection, 1024)) . "<BR>";
32
33 fputs($smtpConnection, "MAIL FROM:<$from>\n");
34 echo htmlspecialchars(fgets($smtpConnection, 1024)) . "<BR>";
35
36 fputs($smtpConnection, "RCPT TO:<$to>\n");
37 echo htmlspecialchars(fgets($smtpConnection, 1024)) . "<BR>";
38
39 fputs($smtpConnection, "DATA\n");
40 echo htmlspecialchars(fgets($smtpConnection, 1024)) . "<BR>";
41
42 fputs($smtpConnection, "Subject: $subject\n");
43 fputs($smtpConnection, "Date: " . date() . "\n");
44 fputs($smtpConnection, "To: <$to>\n");
45 fputs($smtpConnection, "From: <$from>\n");
46 fputs($smtpConnection, "$body\n");
47 fputs($smtpConnection, ".\n");
48 echo htmlspecialchars(fgets($smtpConnection, 1024)) . "<BR>";
49
50 fputs($smtpConnection, "QUIT\n");
51 echo htmlspecialchars(fgets($smtpConnection, 1024)) . "<BR>";
52 echo "</FONT>";
53 }
54 ?>