Link in Email to redirect
Posted: Mon Dec 21, 2009 3:31 pm
Hi All
I am new to php and wanting some help. I need to create a script that emails active articles in my KB to my engineers with the link embedded in the email.
My problem is , once the email reached, the engineer clicks on a link, the login box need to prompt, and he enters his id and password, and once that is authenticated, it has to redirect to the url of the article that he clicked.
Here is a script that i have come so far...
<?php
$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$dbuser="<id>";
$dbpass="<password>";
$dbname="<database>";
$chandle = mysql_connect("localhost", $dbuser, $dbpass) or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle[/color]) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="faqdata"; //The name of the table
$mainsection1="faqnewarticles"; //The name of the table
$query3=sprintf("TRUNCATE faqnewarticles");
$query=sprintf("INSERT INTO faqnewarticles SELECT
faqdata.id,
faqdata.active,
faqdata.thema,
faqdata.datum,
faqcategoryrelations.category_id,
NULL
FROM
faqdata,
faqcategoryrelations
WHERE
faqcategoryrelations.record_id = faqdata.id AND
faqdata.active = 'No'
");
$query2=sprintf("UPDATE faqnewarticles SET newdate = (SELECT LEFT(cast(faqnewarticles.datum as datetime),10))");
$query1=sprintf("SELECT faqnewarticles.thema,faqnewarticles.newdate, faqnewarticles.id, faqnewarticles.category FROM faqnewarticles WHERE faqnewarticles.newdate >= date_sub(curdate(), interval 2 week)");
$result3 = mysql_db_query($dbname, $query3) or die("Failed Query of " . $query3); //do the query
$result1 = mysql_db_query($dbname, $query) or die("Failed Query of " . $query); //do the query
$result2 = mysql_db_query($dbname, $query2) or die("Failed Query of " . $query2); //do the query
$result = mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1); //do the query
$i=0;
while($row = mysql_fetch_array($result))
{
$result_array[$i] = $row;
$i++;
}
$to = "jsolomon@mitchellwayne.com";
$subject = "KB Portal has new articles";
for ($j=0;$j<count($result_array);$j++)
{
$id=$result_array[$j]['id'];
$thema=$result_array[$j]['thema'];
$category=$result_array[$j]['category'];
//$body .= "\n".$result_array[$j]."\n";
$body .= "<br><a href= \"http://kb.hosted.mwedc.com/faq/index.ph ... a."</a><br>";
}
mail($to, $subject,$body, $headers) ;
//mail($to, $subject,$body) ;
mysql_close($chandle);
?>
I am new to php and wanting some help. I need to create a script that emails active articles in my KB to my engineers with the link embedded in the email.
My problem is , once the email reached, the engineer clicks on a link, the login box need to prompt, and he enters his id and password, and once that is authenticated, it has to redirect to the url of the article that he clicked.
Here is a script that i have come so far...
<?php
$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$dbuser="<id>";
$dbpass="<password>";
$dbname="<database>";
$chandle = mysql_connect("localhost", $dbuser, $dbpass) or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle[/color]) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="faqdata"; //The name of the table
$mainsection1="faqnewarticles"; //The name of the table
$query3=sprintf("TRUNCATE faqnewarticles");
$query=sprintf("INSERT INTO faqnewarticles SELECT
faqdata.id,
faqdata.active,
faqdata.thema,
faqdata.datum,
faqcategoryrelations.category_id,
NULL
FROM
faqdata,
faqcategoryrelations
WHERE
faqcategoryrelations.record_id = faqdata.id AND
faqdata.active = 'No'
");
$query2=sprintf("UPDATE faqnewarticles SET newdate = (SELECT LEFT(cast(faqnewarticles.datum as datetime),10))");
$query1=sprintf("SELECT faqnewarticles.thema,faqnewarticles.newdate, faqnewarticles.id, faqnewarticles.category FROM faqnewarticles WHERE faqnewarticles.newdate >= date_sub(curdate(), interval 2 week)");
$result3 = mysql_db_query($dbname, $query3) or die("Failed Query of " . $query3); //do the query
$result1 = mysql_db_query($dbname, $query) or die("Failed Query of " . $query); //do the query
$result2 = mysql_db_query($dbname, $query2) or die("Failed Query of " . $query2); //do the query
$result = mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1); //do the query
$i=0;
while($row = mysql_fetch_array($result))
{
$result_array[$i] = $row;
$i++;
}
$to = "jsolomon@mitchellwayne.com";
$subject = "KB Portal has new articles";
for ($j=0;$j<count($result_array);$j++)
{
$id=$result_array[$j]['id'];
$thema=$result_array[$j]['thema'];
$category=$result_array[$j]['category'];
//$body .= "\n".$result_array[$j]."\n";
$body .= "<br><a href= \"http://kb.hosted.mwedc.com/faq/index.ph ... a."</a><br>";
}
mail($to, $subject,$body, $headers) ;
//mail($to, $subject,$body) ;
mysql_close($chandle);
?>