我正在创建一个免费转发电子邮件地址系统,并在不久前问过这个问题。我想做的是将电子邮件转发给真实的电子邮件地址,同时保持标题不变。是否有任何理由说明以下代码无效:
#!/usr/bin/php -q
<?php
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
$lines = explode("\n", $email);
$to = "";
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
$beforecheck = str_ireplace("to:", "", $to);
$checkdatabase = str_ireplace("@virtualparalegal.com", "", $beforecheck);
mysql_connect("localhost", "virtucb3_admin", "Instant11!") or
die("Could not connect to the Database, the Database returned this error: " . mysql_error());
mysql_select_db("virtucb3_wordpress");
$result = mysql_query("SELECT user_nicename, user_email FROM wp_users WHERE `user_nicename` = $checkdatabase");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ( $row["user_nicename"] == "$checkdatabase") {
$to = ($row["user_email"]);
}
else {
$to = "info@virtualparalegal.com";
}
}
for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {
$headers .= $lines[$i]."\n";
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
$splittingheaders = false;
}
}
mail($to, $subject, $message, $headers);
?>
提前谢谢大家。