実際に私の独自の関数を作成していないので、私が試しているのはfunction NewsUpdate
という行の下のスクリプトを開始することです。 if文では、スクリプトが「電子メールメッセージ」の文字列「News Update」を見つけた場合、それらのスクリプトを開始します。そうでない場合は(else文が一番下にあります)失敗し、「News Update not found電子メールメッセージ」エラーPHPを使用したif文の後に関数を開始する
にしかし、私はエラーを取得:
Parse error: syntax error, unexpected T_FUNCTION
私は間違って何をしているのですか?
// Test code for email message.
$open_email_msg = file_get_contents('emailmessage.html');
// A script that searches the e-mail for the string News Update,
// and if it is found it will start the function NewsUpdate
if(strpos($open_email_msg,"News Update"))
function NewsUpdate ($open_email_msg) {
// Login to MySQL Datebase
$hostname = "localhost";
$db_user = "user";
$db_password = "pass";
$database = "tablename";
$db_table = "bx_news_entries";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$subject = 'Test News Article';
$tags = str_replace(' ',',',$subject); // DDIE
$uri = str_replace(' ','-',$subject); // DDIE
$when = strtotime("now"); // date article was posted
$categories = 'Events';
$content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
$snippet = 'Lorem ipsum dolor sit amet.';
// $snippet = explode(".", $content, -1);
# THIS CODE WILL TELL MYSQL TO INSERT THE DATA FROM THE EMAIL INTO YOUR MYSQL TABLE
$sql = "INSERT INTO $db_table(`caption`, `snippet`, `content`, `when`, `uri`, `tags`, `categories`, `DATE`) values ('$subject', '$snippet', '$content', '$when', '$uri', '$tags', '$categories', '$when')";
if($result = mysql_query($sql ,$db)) {
} else {
echo "ERROR: ".mysql_error();
}
echo "<h1>News Article added!</h1>";
}
else {
echo "<h3>'News Update</h3>not found in e-mail message!";
}
ありがとう、これは完了しました。 –