Jump to content

Recommended Posts

Hi

 

I'm trying to write up a script from scratch which will check a database to verify the lifespan of a page and then if the expiry date has been reached and/or exceded, it will email the page owner to warn of an impending deletion.

 

This is probably terrible, inefficient code and if there are any other suggestions- i'll defo listen to them! But for now I keep getting this message when I load the page:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /web/vhosts/arts/test/philotest.php on line 22

 

Line 22 is the last one beginning "mail($..."

I think I'm on the right track but I'm starting to make a bit of a balls of it...

 

<?php
### email variables ###
$cur_date =  date('Y-m-d');
$subject = "Page content expired?";
$text = "Please check the content of the following page- http://www.coalduststar.com/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$expdate.". Please contact the designer responsible for this page (".$row_owner['page_name']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You.";

### Gets page name and stores it to variable ###
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_name1 = $parts[count($parts) - 1];

### Recordset filtered to page name ###
mysql_select_db($database_ownership, $ownership);
$query_owner = "SELECT * FROM arts_ownership_history Where page_name = '$page_name1'";
$owner = mysql_query($query_owner, $ownership) or die(mysql_error());
$row_owner = mysql_fetch_assoc($owner);
$totalRows_owner = mysql_num_rows($owner);

### Mail function (if page is out of date?) ###
if($row_owner['page_expdate'] >=  strtotime($cur_date) && $row_owner['$emailyn'] > 0){
mail($row_owner['page_owner_email'], $subject, $text, "From: $row_owner['page_author'] <$row_owner['page_author_email']>");

}


?>

 

thanks ;)

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/
Share on other sites

### Mail function (if page is out of date?) ###
if($row_owner['page_expdate'] >=  $cur_date && $row_owner['$emailyn'] > 0){
mail($row_owner['page_owner_email'], $subject, $text, "From: $row_owner['page_author'] <$row_owner['page_author_email']>");
}

Update- changed "strtotime($cur_date)" to "$cur_date" cos it didn't match the "DATE" data type inthe database- still the same error but now it's on the final line of the mail function which is essentially just a "}"

 

no ideas?  :-\

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-432758
Share on other sites

Just to continue this monologue... :P - This no longer produces an error but it doesn't work either. What it's supposed to do is compare the current date to the date in the database and if the current date is equal to or excedes the stored date AND the value in the column page_emailyn is greater than "0", then I want the mailer to send an email to the page owner.

 

Could someone point me in the direction of what i've done wrong- i think the insert a record stuff is wrong but I though the mailer would work at least  ???

 

Please- i'm stumped!

 

 

<?php require_once('../Connections/ownership.php'); ?>
<?php
### current date ###
$cur_date =  date('Y-m-d');

### Gets page name and stores it to variable ###
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_name1 = $parts[count($parts) - 1];

### Recordset filtered to page name ###
mysql_select_db($database_ownership, $ownership);
$query_owner = "SELECT * FROM arts_ownership_history Where page_name = '$page_name1'";
$owner = mysql_query($query_owner, $ownership) or die(mysql_error());
$row_owner = mysql_fetch_assoc($owner);
$totalRows_owner = mysql_num_rows($owner);


### Mail function (if page is out of date?) ###
$owner = $row_owner['page_owner_email'];
$subject = "Page content expired?";
$text = "Please check the content of the following page- http://www.arts.ulster.ac.uk/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$row_owner['page_expdate'].". Please contact the designer responsible for this page (".$row_owner['page_author']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You.";
$author = $row_owner['page_author'];
$email = $row_owner['page_author_email'];

if($row_owner['page_expdate'] >=  $cur_date && $row_owner['$page_emailyn'] > 0){
mail($owner,$subject,$text,"From: $author <$email>");
$row_owner['$emailyn'] = 1;
$insertSQL = sprintf("INSERT INTO arts_ownership_history(page_emailyn) VALUES 1");

mysql_select_db($database_ownership, $ownership);
  $Result1 = mysql_query($insertSQL, $ownership) or die(mysql_error());

}




?>

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-434659
Share on other sites

Thanks- that looks a lot more efficient than what I had in before with all those variables but it didn't really change anything- there aren't any errors but the database isn't updating and the email isn't going out. thanks for taking a look!

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-434670
Share on other sites

Can no-one point me in the right direction? I think it might be the part where I'm updating the database?

 

<?php require_once('../Connections/ownership.php'); ?>
<?php
### current date ###
$cur_date =  date('Y-m-d');

### Gets page name and stores it to variable ###
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_name1 = $parts[count($parts) - 1];

### Recordset filtered to page name ###
mysql_select_db($database_ownership, $ownership);
$query_owner = "SELECT * FROM arts_ownership_history Where page_name = '$page_name1'";
$owner = mysql_query($query_owner, $ownership) or die(mysql_error());
$row_owner = mysql_fetch_assoc($owner);
$totalRows_owner = mysql_num_rows($owner);


### Mail function (if page is out of date?) ###
$subject = "Page content expired?";
$text = "Please check the content of the following page- http://www.arts.ulster.ac.uk/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$row_owner['page_expdate'].". Please contact the designer responsible for this page (".$row_owner['page_author']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You.";

if($row_owner['page_expdate'] >=  $cur_date && $row_owner['$page_emailyn'] > 0){

mail($row_owner['page_owner_email'], $subject, $text, "From: {$row_owner['page_author']} <{$row_owner['page_author_email']}>");

$row_owner['$emailyn'] = 1;
$insertSQL = sprintf("INSERT INTO arts_ownership_history(page_emailyn) VALUES 1");

mysql_select_db($database_ownership, $ownership);
  $Result1 = mysql_query($insertSQL, $ownership) or die(mysql_error());

}




?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435481
Share on other sites

Does the code look alright? It's not updating the database or sending out the email. I've set a record in the database with an expiry date before today's date. What's supposed to happen, if today's date is greater than the expiry date is that the mail() function should send and email out and also change a value in the page_emailyn column from 0 to 1 so that in the future, when this page is accessed, the email won't send everytime.

 

Does that make any sense- it's to notify people to check the content of the pages to make sure it's up-to-date.

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435537
Share on other sites

nope...  :-\

 

still no errors but no action either and i've just realised what i've done is totally wrong- how would i get the date into the right format if it's in the wrong format to begin with?

 

Changed to this:

if(date($row_owner['page_expdate'], 'Y-m-d') >=  $cur_date && $row_owner['$page_emailyn'] > 0){

 

and the error i get is:

Warning: date() expects parameter 2 to be long, string given in /web/vhosts/arts/test/philotest.php on line 23

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435566
Share on other sites

Ok i think this little script will search your database and echo any dates from the past. Lets get that working then we can start on the mail script. Make sure you change the date column name

 


<?php require_once('../Connections/ownership.php')

//current date 
$cur_date =  date('Y-m-d');



// Recordset filtered to page name
mysql_select_db($database_ownership, $ownership);
$query_owner = "SELECT * FROM arts_ownership_history Where  datecol < CURDATE() ";
$owner = mysql_query($query_owner) or die(mysql_error());
while($row_owner = mysql_fetch_assoc($owner))
{
echo $row_owner['datecol'];
}


//change datecol to the name of the column that stores the expiry date.



?>

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435599
Share on other sites

Ok that works 100% but i'm probably not explaining this correctly- i'm kind of trying to only pull the record that corresponds to this page.  It's going to a database with the page names and expiry dates of the content.

 

Then this code i'm busy butchering into nothing at the minute is going to be in the top of every php page so that whenever a user accesses the page the expiry date in the database that is checked against the current date and if the page has exceeded the date AND an email hasn't been sent previously (there's a boolean value in the database to record if an email has been sent) then the mail will send and the database will be told to change the boolean value to recrod that the email has been sent and to ensure that it isn't resent.

 

But if this is part of fixing process then "hit me" cos it's driving me a bit mad! :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435618
Share on other sites

this is part of the process. LOL you can now search a database for passed dates. Therefore that will form the top part of every page. If this part of the code works

[code]
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_name1 = $parts[count($parts) - 1];

 

Then we can do this

 


<?php require_once('../Connections/ownership.php')

//current date 

$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_name1 = $parts[count($parts) - 1];

 

 

// Recordset filtered to page name

mysql_select_db($database_ownership, $ownership);

$query_owner = "SELECT * FROM arts_ownership_history Where  datecol < CURDATE() AND pagename = $page_name1 ";

$owner = mysql_query($query_owner) or die(mysql_error());

while($row_owner = mysql_fetch_assoc($owner))

{

echo $row_owner['datecol'];

}

 

 

//change datecol to the name of the column that stores the expiry date.

 

?>

 

[/code]

That will get everything from the database that has a certain page_name and the expiry date has passed. Tweek the code and get it to work.

 

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435659
Share on other sites

LOL- right you are- sorry about that!

realised that CURDATE in the sql eliminates the date check thing so i just have to check if the emailyn field is populated but it still won't fire out a mail.

 

 

<?php
### current date ###
$cur_date =  date('Y-m-d');

### Gets page name and stores it to variable ###
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_name1 = $parts[count($parts) - 1];

### Recordset filtered to page name ###
mysql_select_db($database_ownership, $ownership);
$query_owner = "SELECT * FROM arts_ownership_history WHERE  page_expdate < CURDATE() AND page_name = '$page_name1'";
$owner = mysql_query($query_owner, $ownership) or die(mysql_error());
$row_owner = mysql_fetch_assoc($owner);
$totalRows_owner = mysql_num_rows($owner);


### Mail function (if page is out of date?) ###
$subject = "Page content expired?";
$text = "Please check the content of the following page- http://www.arts.ulster.ac.uk/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$row_owner['page_expdate'].". Please contact the designer responsible for this page (".$row_owner['page_author']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You.";

if($row_owner['$page_emailyn'] < 0){

mail($row_owner['page_owner_email'], $subject, $text, "From: {$row_owner['page_author']} <{$row_owner['page_author_email']}>");

$row_owner['$emailyn'] = 1;
$insertSQL = sprintf("INSERT INTO arts_ownership_history(page_emailyn) VALUES 1");

mysql_select_db($database_ownership, $ownership);
  $Result1 = mysql_query($insertSQL, $ownership) or die(mysql_error());

}




?>

 

 

just as an aside- you know the way phpself gets the filename and extension- is there a way to get the entire address "http://...philotest.php"? Cos that would eliminate the fact that more than one record can have the same file name?

Link to comment
https://forums.phpfreaks.com/topic/84885-mailer/#findComment-441927
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.