OK, here's what I got so far: (i've trimmed the html code down to the relevant bits)
jobsmailselect (where we do the ticking):
<form action="eventadmin/jobsmail.php" method="post">
<?php while ($row = mysql_fetch_array($result))
{
?>
<tr>
<td><a href="jobsfull.php?id=<?php echo $row['id'];?>"><?php echo $row['jobtitle'];?></a></td>
<td><?php echo date("d M Y", $row['dateadded']);?></td>
<td><?php echo date("d M Y", $row['closingdate']);?></td>
<!--Link to edit info-->
<td><input type="checkbox" name="send[<?php echo $row['id'];?>" value="checkbox"></td>
</tr>
<?php
}
?>
Now, this was definitely sending something to jobsmail.php, but rather than populating a textarea as I expected, it went straight to send the email, but obviously (thankfully!) got caught up in the error checking. I think this is something to do with the way i have jobsmail.php set up. Jobsmail.php was working when I manually filled in the information - on clicking 'send' it sent the mail. In this case there IS a $_POST['submit'], but rather than coming from itself, it's coming from jobselect.php. I think this is why it's trying to 'send' too soon, but I can't figure how to reorder the structure. Would it be best to make the form in jobsmail.php point to a third page which does the sending?
Here's the code for jobsmail.php:
<?php
//if the form has not been posted, display the form for the text to be entered into
if (!$_POST['submit'])
{
if (!isset($_GET[$jobsend]))
{
echo 'sorry, you have not selected any jobs to put in the email';
}
else
{
require_once('../../sypphp/sypcms/DbConnector.php');
$connector = new DbConnector();
foreach($jobsend as $id)
{
$result = mysql_query('SELECT id, company, jobtitle, jobdesc, contact, , DATE_FORMAT(closingdate,"%d %M %Y") AS closingdate FROM jobs WHERE id = "$id" ORDER BY closingdate ASC');
}//end foreach
}//end if !isset
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table width=100% align="center">
<tr>
<td width="20%">From Name:</td>
<td width="80%" align="left"><input type="text" name="from" size="30"></td>
</tr>
<tr>
<td>From email:</td>
<td align="left"><input name="frommail" type="text" id="frommail" size="30"></td>
</tr>
<tr>
<td width="20%"> Subject </td>
<td width="80%" align="left"><input name="subject" type="text" id="author" size="30"></td>
</tr>
<tr>
<td>Body</td>
<td align="left"><textarea name="body" cols="50" rows="15">
<?php
while ($row = mysql_fetch_array($result))
{
echo'<p><h3>'.$row['company'].'<br></h3><h4>'.$row['jobtitle'].'</h4>';
echo'<p>'.$row['jobdesc'].'</p>';
echo'<p><b>How to apply</b><br>'.$row['contact'].'</p>';
echo'<p><b>Closing Date: </b>'.$row['closingdate'].'</p><hr>';
}
?>
</textarea></td>
</tr>
</table>
<div align="center"><input type="Submit" name="submit" value="Send Mail">
</div>
</form>
<?php
}
else
//CONTENT HAS BEEN ADDED AND SUBMITTED - BUILD QUERY TO GET USERS AND EMAIL INFORMATION
{
$errorlist = array();
$postfrom = $_POST['from'];
$postfrommail = $_POST['frommail'];
$postsubj = $_POST['subject'];
$posthtml = $_POST['body'];
$posttext = nl2br(strip_tags($posthtml));
if (trim($_POST['from']) == '') {$errorlist[] = 'You need to enter the sender\'s email address';}
if (trim($_POST['subject']) == '') {$errorlist[] = 'You need to enter a subject';}
if (trim($_POST['body']) == '') {$errorlist[] = 'You need to enter some body';}
if (sizeof($errorlist) !== 0)
{
echo 'The following errors have been encountered:<br>';
foreach ($errorlist as $value)
{
echo $value . '<br>';
}
} //end if errors
else
{
require_once('../../sypphp/sypcms/DbConnector3.php');
$connector = new DbConnector();
$mailinglist = mysql_query('SELECT * FROM mailinglist') or die(mysql_error());
if (mysql_num_rows($mailinglist) > 0)
{
echo 'Mail sent to: <br>';
while ($mail = mysql_fetch_array($mailinglist))
{
$name = $mail['name'];
$to = $mail['email'];
// {
// echo $mail['name'].' '.$mail['email'].'<br>';
// }
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/MailClass.inc');
// instantiate the class
$mailer = new FreakMailer();
// Set From name & address
$mailer->FromName = $postfrom;
$mailer->From = $postfrommail;
// Set Reply address
$mailer->AddReplyTo($postfrommail, $postfrom);
// Set the subject
$mailer->Subject = $postsubj;
// Body
$htmlBody = '<b>My</b><i>HTML</i> Body....';
$textBody = strip_tags($htmlBody);
$mailer->Body = $posthtml;
$mailer->isHTML(true);
$mailer->AltBody = $posttext;
// Send the mail...
// Add an address to send to.
$mailer->AddAddress($to, $name);
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
echo 'mail sent to '.$name.', '.$to.'<br>';
} //end while
echo '<a href="/index.php">Click to return to the index page</a>';
}//end elseif rows
}//end error check
} //end elseif submitted
?>