I have set up a page that presents data from a MYSQL dbase, and then sends the information as an email when one submits a recipient's email address. It also sends me a notification email.
As you can see below the recordset (restSelect) is selected by receipt of a POSTed numerical variable from a previous page.
The page works to the extent that the correct data is drawn from the dbase and presented on the webpage, but when the emails are sent the messages arrive without the dbase info.
I don't understand why the emails are not collecting the data. Can anyone see where I'm going wrong, please?
(php written largely by DW2004)
Here's the code:
Many thanks for looking.
Steve
As you can see below the recordset (restSelect) is selected by receipt of a POSTed numerical variable from a previous page.
The page works to the extent that the correct data is drawn from the dbase and presented on the webpage, but when the emails are sent the messages arrive without the dbase info.
I don't understand why the emails are not collecting the data. Can anyone see where I'm going wrong, please?
(php written largely by DW2004)
Here's the code:
Code:
<?php require('../../Connections/tormented3.php'); ?>
<?php
$colname_restSelect = "1";
if (isset($_POST['org_pk'])) {
$colname_restSelect = (get_magic_quotes_gpc()) ? $_POST['org_pk'] : addslashes($_POST['org_pk']);
}
mysql_select_db($database_tormented3, $tormented3);
$query_restSelect = sprintf("SELECT * FROM cel_contents WHERE cel_pk = %s", $colname_restSelect);
$restSelect = mysql_query($query_restSelect, $tormented3) or die(mysql_error());
$row_restSelect = mysql_fetch_assoc($restSelect);
$totalRows_restSelect = mysql_num_rows($restSelect);
if(isset($_POST['send'])){ // 'submit' is the name of your submit button
$error = '';
// process and validate a field:
$email1 = trim($_POST['email1']);
if($email1 == ''){ // if name is empty, show an error message (us that for required fields)
$error .= '<p style="color:red;">You missed out your email address!</p>'; // error message
}
if($error == ''){ // if no error, process the form
// Mail script
$org = $row_restSelect['cel_org'];
$tel = $row_restSelect['cel_tel'];
$message = "Thank you for requesting information about $org.\n\n"; // Set up the email message to the client.
$message .= "Contact Details: \n";
$message .= "Tel No. $tel \n";
$inform_me = "Details of $org have been sent to $email1"; // Set up the email to inform me of the information request.
// The emails:
if(mail("$email1", $org, $message, "From: [URL unfurl="true"]www.somewhere.org.uk")[/URL] && mail("feedback@somewhere.org.uk", $org,
$inform_me, "From: [URL unfurl="true"]www.somewhere.org.uk"))[/URL]
{
header('location: [URL unfurl="true"]http://www.somewhere.org.uk/feedback/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
exit;
}else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try
again</p>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Feedback Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="fb.js"></script>
<link href="../css/mentalhealth_bx.css" rel="stylesheet" type="text/css" />
</head>
<body class="grey_bground" >
<form action="<?php echo $PHP_SELF; ?>" method="post" name="email1" id="email1">
<?php echo $error; ?>
<!-- Call the processing routine -->
<div id="wrapper"> <!-- This div code sometimes appears red in DW because there are 2 closing /divs (see below) -->
<table class="whitecell" cellpadding="1">
<tr>
<td colspan="4" class="cellcolour"><p align="center" class="redhaed">NB. This Email Form is not yet functioning correctly </p>
<p align="center" class="strongbody">Use this form to send the information below about <span class="redhaed"><?php echo $row_restSelect['cel_org']; ?></span> to yourself, or to someone else<br />
by entering the relevant email address in the space below.<br />
</p>
</td>
</tr>
<tr>
<td align="right"><p> </p>
<p> </p></td>
<td colspan="3" valign="top"> <?php echo $org_pk; //temporary check ?></td>
</tr>
<tr>
<td align="right"><span class="right_cell">Information about</span></td>
<td colspan="3" valign="top"><?php echo $row_restSelect['cel_org']; ?> from [URL unfurl="true"]www.somewhere.org.uk[/URL] </td>
</tr>
<tr>
<td colspan="4" align="right"> </td>
</tr>
<tr>
<td align="right" class="right_cell">Tel.no. </td>
<td><?php echo $row_restSelect['cel_tel']; ?> </td>
</tr>
<tr>
<td valign="top" class="right_cell"> </td>
<td valign="top"> </td>
</tr>
<tr>
<td colspan="4" valign="top"></td>
</tr>
<tr>
<td align="right" class="cellcolour">
Recipient's email address:<b> <br />
</b></td>
<td><input name="email1" type="text" size="40" value="" />
<input name="send" type="submit" value=" Send " />
</td>
</tr>
<tr>
<td colspan="2"><div align="right"></div></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php
mysql_free_result($restSelect);
?>
Steve