script within a script.. or not
Posted: Sat Dec 27, 2008 7:16 am
I decided to remove this post as it potentially revealed coding i don't want in the public arena
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
not madness I assure you - this is to alert doctors who are wanting receive emails regarding new work as and when it is posted to the website - they can opt out by unticking their box on their profilecalifdon wrote:Do you really want it to send these emails every time you update the database with a new record?
Code: Select all
include("connect.php");
// these are my variables to convert the form data //
$practice = $_POST['practice'];
$date_posted = $_POST['date_posted'];
$job_start_date = $_POST['job_start_date'];
$job_end_date = $_POST['job_end_date'];
$contact = $_POST['contact'];
$session_visible = $_POST['session_visible'];
$accepted_by = $_POST['accepted_by'];
$job_details = $_POST['job_details'];
$results = mysql_query($query) or die
("Could not execute query : $query." . mysql_error());
// these lines pass the information into the job table //
$query = "INSERT INTO job (id, practice, date_posted, job_start_date, job_end_date, contact, session_visible, accepted_by, job_details)
VALUES ('', '$practice', CURRENT_TIMESTAMP, '$job_start_date', '$job_end_date', '$contact', 'Y', '$accepted_by', '$job_details')";
// defining the variables for use in the outbound email //
$from = "From: OxNoG Jobs <admin@oxnog.org>";
$subject = "New Job alert";
$body = "$contact from $practice has posted a new job advertisement starting on $job_start_date and finishing on $job_end_date. To review the details, log in to the database at http://www.oxnog.org using password: nogger If the job does not appear in the database, it is because the session has already been filled, and the practice manager has de-activated the session.
Contact the Group Administrator on admin@oxnog.org if you need help";
// now I'm setting up a loop to send out a series of emails to the members who have chosen to receive updates //
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * from doctors WHERE (working='Y' AND validated='Y')";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$emailaddy=mysql_result($result,$i,"email");
mail($emailaddy,$subject,$body,$from);
$i++;
}
// I'll need to add an echo here to tell the person posting the advert to the database that their post has been added and distributed successfully ok later on //
Code: Select all
...
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * from doctors WHERE (working='Y' AND validated='Y')";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) {
$emailaddy=$row['email'];
mail($emailaddy,$subject,$body,$from);
}
...I'm not partic concerned about this as they will bounce to the administrators email account, and any such errors will need to be ironed out pronto if they happen - there's only a limited number of punters using the database so it should be manageable.Auselan wrote:could add refinements such as intercepting any errors from the mail() function, such as caused by an invalid email address
Code: Select all
<?php
include("connect.php");
$practice = $_POST['practice'];
$date_posted = $_POST['date_posted'];
$job_start_date = $_POST['job_start_date'];
$job_end_date = $_POST['job_end_date'];
$contact = $_POST['contact'];
$session_visible = $_POST['session_visible'];
$accepted_by = $_POST['accepted_by'];
$job_details = $_POST['job_details'];
$query = "INSERT INTO job (id, practice, date_posted, job_start_date, job_end_date, contact, session_visible, accepted_by, job_details)
VALUES ('', '$practice', CURRENT_TIMESTAMP, '$job_start_date', '$job_end_date', '$contact', 'Y', '$accepted_by', '$job_details')";
$results = mysql_query($query) or die
("Could not execute query : $query." . mysql_error());
if ($results)
{
echo "Details added.";
}
// defining the variables for use in the outbound email //
$from = "From: OxNoG Jobs <admin@oxnog.org>";
$subject = "New Job alert";
$body = "$contact from $practice has posted a new job advertisement starting on $job_start_date and finishing on $job_end_date. To review the details, log in to the database at http://www.oxnog.org using password: nogger If the job does not appear in the database, it is because the session has already been filled, and the practice manager has de-activated the session.
Contact the Group Administrator on admin@oxnog.org if you need help";
// now I'm setting up a loop to send out a series of emails to the members who have chosen to receive updates //
mysql_select_db($dbase) or die( "Unable to select database");
$query="SELECT * from doctors WHERE (working='Y' AND validated='Y')";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) {
$emailaddy=$row['email'];
mail($emailaddy,$subject,$body,$from);
}
?>
<link href="/CSS/colors5.css" rel="stylesheet" type="text/css" />
Emails have been generated to all doctors with full membership who are looking for Locum work<br>
<a href="shortindex.php">click here to go back to the Job index and view/modify the advert</a>