2 ////////////////////////////////////////////////////
3 // mailerc - phpmailer client
5 // Version 0.07, Created 2001-01-03
7 // Client application for sending outgoing
8 // messages from a file.
10 // Author: Brent R. Matzelle <bmatzelle@yahoo.com>
12 // License: LGPL, see LICENSE
13 ////////////////////////////////////////////////////
15 require("class.phpmailer.php");
17 // Gather global server arg variables
19 $_SERVER = $HTTP_SERVER_VARS;
20 $cargv = $_SERVER["argv"];
21 $cargc = $_SERVER["argc"];
23 define("PROG_VERSION", "0.01");
24 define("PROG_NAME", $cargv[0]);
25 @set_time_limit
(0); // unlimited
27 // Ignore warning messages
28 error_reporting(E_ERROR
);
31 * mailerc - mailerc extension class
32 * @author Brent R. Matzelle
34 class mailerc
extends phpmailer
37 * Send an email from a file created with the
38 * SendToQueue() function.
42 function SendFromFile($filePath) {
48 // Make sure is there and accessible
49 if(!is_file($filePath))
51 $this->error_handler(sprintf("Cannot access: %s", $filePath));
55 // upon getting header do not forget to gather the
56 // server info (date, recieved())
57 $qarray = file($filePath);
59 if(count($qarray) < 1)
61 $this->error_handler("Invalid queue file");
65 // Create the header and the body (just set header)
66 $header = $this->received();
67 $header .= sprintf("Date: %s\r\n", $this->rfc_date());
70 for($i = 0; $i < count($qarray); $i++
)
72 if($qarray[$i] == "----END PQM HEADER----\r\n")
79 for($i = $msg_start; $i < count($qarray); $i++
)
82 $this->Mailer
= $this->qvar($qarray, "Mailer");
83 if($this->Mailer
== "sendmail")
85 $this->Sendmail
= $this->qvar($qarray, "Sendmail");
86 $this->Sender
= $this->qvar($qarray, "Sender");
88 if(!$this->sendmail_send($header, $body))
91 elseif($this->Mailer
== "mail")
93 $this->Sender
= $this->qvar($qarray, "Sender");
94 $this->Subject
= $this->qvar($qarray, "Subject");
96 $to_list = explode(";", $this->qvar($qarray, "to"));
97 for($i = 0; $i < count($to_list); $i++
)
98 $this->AddAddress($to_list[0], "");
100 // This might not work because of not sending
101 // both a header and body.
102 if(!$this->mail_send($header, $body))
105 elseif($this->Mailer
== "smtp")
107 $this->Host
= $this->qvar($qarray, "Host");
108 $this->Port
= $this->qvar($qarray, "Port");
109 $this->Helo
= $this->qvar($qarray, "Helo");
110 $this->Timeout
= $this->qvar($qarray, "Timeout");
111 $this->SMTPAuth
= (int)$this->qvar($qarray, "SMTPAuth");
112 $this->Username
= $this->qvar($qarray, "Username");
113 $this->Password
= $this->qvar($qarray, "Password");
114 $this->From
= $this->qvar($qarray, "From");
116 $to_addr = $this->qvar($qarray, "to");
119 $to_list = explode(";", $to_addr);
120 for($i = 0; $i < count($to_list); $i++
)
121 $this->AddAddress($to_list[0], "");
124 $to_addr = $this->qvar($qarray, "cc");
127 $to_list = explode(";", $to_addr);
128 for($i = 0; $i < count($to_list); $i++
)
129 $this->AddCC($to_list[0], "");
132 $to_addr = $this->qvar($qarray, "bcc");
135 $to_list = explode(";", $to_addr);
136 for($i = 0; $i < count($to_list); $i++
)
137 $this->AddBCC($to_list[0], "");
140 if(!$this->smtp_send($header, $body))
145 $this->error_handler(sprintf("%s mailer is not supported", $this->Mailer
));
153 * Return the given queue variable from the pqm header file. Returns
154 * an empty string if the data was not found.
158 function qvar($qarray, $data) {
160 $pqm_marker = "----END PQM HEADER----\n";
162 while($qarray[$i] != $pqm_marker)
164 $item = explode(": ", $qarray[$i]);
165 //echo $item[0] . "\n"; // debug
166 if($item[0] == $data)
167 return rtrim($item[1]);
171 return ""; // failure
176 * Print out the program version information.
180 function print_version()
182 printf("mailerc %s - phpmailer client\n\n" .
183 "This program is distributed in the hope that it will be useful,\n" .
184 "but WITHOUT ANY WARRANTY; without even the implied warranty of \n" .
185 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" .
186 "GNU Lesser General Public License for more details.\n\n" .
187 "Written by: Brent R. Matzelle\n", PROG_VERSION
);
191 Print out the help message to the console.
195 function print_help()
197 printf("mailerc %s, phpmailer queue daemon.\n", PROG_VERSION
);
198 printf("Usage: %s [OPTION] [FILE]\n", PROG_NAME
);
201 -h, --help print this help.
202 -V, --version print version information.
203 -s, --send send [FILE]\n");
207 * Sends a given message from a pqm (Phpmailer Queue Message) file.
211 function send_message($filePath)
213 // Open the file and read the header contents and set
214 // another message. Then run the phpmailer send file.
215 $mail = new mailerc();
216 if(!$mail->SendFromFile($filePath))
217 printf("error: %s\n", $mail->ErrorInfo
);
219 printf("success: sent\n");
243 send_message($cargv[2]);
249 return 0; // return success