added "reply-to" capabilities
[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, $username, $domain, $t, $c, $b, $subject, $body, $version) {
20 $to = parseAddrs($t);
21 $cc = parseAddrs($c);
22 $bcc = parseAddrs($b);
23 $body = stripslashes($body);
24 $from = "$username@$domain";
25
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>";
31 exit;
32 }
33
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? */
40 fputs($smtpConnection, "MAIL FROM:<$from>\n");
41
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 }
52
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
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
66 echo "</FONT>";
67 }
68 ?>