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) { |
7831268e |
20 | include("../config/config.php"); |
21 | |
40ee9452 |
22 | $to = parseAddrs($t); |
23 | $cc = parseAddrs($c); |
24 | $bcc = parseAddrs($b); |
4f96d941 |
25 | $body = stripslashes($body); |
c175e2e4 |
26 | $from = "$username@$domain"; |
27 | |
b8ea4ed6 |
28 | echo "<FONT FACE=\"Arial,Helvetica\">"; |
c175e2e4 |
29 | $smtpConnection = fsockopen($smtpServerAddress, $smtpPort, $errorNumber, $errorString); |
b8ea4ed6 |
30 | if (!$smtpConnection) { |
31 | echo "Error connecting to SMTP Server.<br>"; |
32 | echo "$errorNumber : $errorString<br>"; |
33 | exit; |
7831268e |
34 | } else { |
35 | $tmp = fgets($smtpConnection, 1024); |
b8ea4ed6 |
36 | } |
b8ea4ed6 |
37 | |
40ee9452 |
38 | $to_list = getLineOfAddrs($to); |
39 | $cc_list = getLineOfAddrs($cc); |
40 | |
41 | /** Lets introduce ourselves */ |
42 | fputs($smtpConnection, "HELO $domain\n"); |
7831268e |
43 | |
40ee9452 |
44 | /** Ok, who is sending the message? */ |
c175e2e4 |
45 | fputs($smtpConnection, "MAIL FROM:<$from>\n"); |
b8ea4ed6 |
46 | |
40ee9452 |
47 | /** send who the recipients are */ |
48 | for ($i = 0; $i < count($to); $i++) { |
49 | fputs($smtpConnection, "RCPT TO:<$to[$i]>\n"); |
50 | } |
51 | for ($i = 0; $i < count($cc); $i++) { |
52 | fputs($smtpConnection, "RCPT TO:<$cc[$i]>\n"); |
53 | } |
54 | for ($i = 0; $i < count($bcc); $i++) { |
55 | fputs($smtpConnection, "RCPT TO:<$bcc[$i]>\n"); |
56 | } |
b8ea4ed6 |
57 | |
40ee9452 |
58 | /** Lets start sending the actual message */ |
b8ea4ed6 |
59 | fputs($smtpConnection, "DATA\n"); |
7831268e |
60 | |
40ee9452 |
61 | fputs($smtpConnection, "Subject: $subject\n"); // Subject |
8405ee35 |
62 | fputs($smtpConnection, "From: <$from>\n"); // Subject |
40ee9452 |
63 | fputs($smtpConnection, "To: <$to_list>\n"); // Who it's TO |
7831268e |
64 | |
40ee9452 |
65 | if ($cc_list) { |
66 | fputs($smtpConnection, "Cc: <$cc_list>\n"); // Who the CCs are |
67 | } |
68 | fputs($smtpConnection, "X-Mailer: SquirrelMail (version $version)\n"); // Identify SquirrelMail |
7ce342dc |
69 | fputs($smtpConnection, "Reply-To: $from\n"); |
70 | fputs($smtpConnection, "MIME-Version: 1.0\n"); |
4809f489 |
71 | fputs($smtpConnection, "Content-Type: text/plain\n"); |
40ee9452 |
72 | |
73 | fputs($smtpConnection, "$body\n"); // send the body of the message |
7831268e |
74 | |
40ee9452 |
75 | fputs($smtpConnection, ".\n"); // end the DATA part |
76 | fputs($smtpConnection, "QUIT\n"); // log off |
b8ea4ed6 |
77 | echo "</FONT>"; |
78 | } |
79 | ?> |