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 | |
c175e2e4 |
19 | function sendMessage($smtpServerAddress, $smtpPort, $to, $subject, $body) { |
20 | $to = addslashes($to); |
21 | $body = addslashes($body); |
22 | $from = "$username@$domain"; |
23 | |
b8ea4ed6 |
24 | echo "<FONT FACE=\"Arial,Helvetica\">"; |
c175e2e4 |
25 | $smtpConnection = fsockopen($smtpServerAddress, $smtpPort, $errorNumber, $errorString); |
b8ea4ed6 |
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 | |
c175e2e4 |
33 | fputs($smtpConnection, "MAIL FROM:<$from>\n"); |
b8ea4ed6 |
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"); |
c175e2e4 |
43 | fputs($smtpConnection, "Date: " . date() . "\n"); |
44 | fputs($smtpConnection, "To: <$to>\n"); |
45 | fputs($smtpConnection, "From: <$from>\n"); |
b8ea4ed6 |
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 | ?> |