Haven’t really create my own function before, so what I am attempting is to start the scripts below the line function NewsUpdate, but I want them to be apart of the function. In the if statement, when the script finds the string “News Update” in the ’email message’ it will start those scripts, if not (the else statement all the way at the bottom) it will fail and say “News Update not found in e-mail message”
But I get the error:
Parse error: syntax error, unexpected T_FUNCTION
What am I doing wrong?
// 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!";
}
move your function above and call it: