I want to set up a simple 'mail this job to a friend' area. I have gotten as far as opening the new page with the appropriate ID, populating the resulting page, error checking the fields and even emailing the page to the appropriate person.
Where I'm stuck is how to grab data from my database and put it into the resulting mail() function. It doesn't seem to work normally.
I'm also not having luck getting the get_env("HTTP_REFERER") to work correctly, as it's not passing from my function in a variable to the second case statement in my page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
//local connect
$db= mysql_connect("localhost", "someusername", "somepassword")
or die("Could not connect: " . mysql_error());
mysql_select_db("Jobs",$db);
function sendform(){
$sql = "select * from wowjobs WHERE id = '".$_GET['jobid']."'";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
while ($row=mysql_fetch_array($result)) {
?>
<form method="post" action="<?php echo $PHP_SELF; ?>?goto=mail">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<!-- BEGIN: Main Content Table -->
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#ffffff"><img src="/roving/images/spacer.gif" alt="" width="1" height="1" border="0"></td>
<td class="mainfont" bgcolor="#ffffff" align="center">
<div align="left"><font color="#000099">Fill in the boxes below to
send a personalized copy of this job listing to a friend.</font> <br>
<!-- BEGIN: form -->
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="mainboldfont"><font color="#000099">Job ID: <?php echo $row['id']; ?></font></td>
<td class="mainboldfont"><font color="#000099">Job Title: <?php $jobtitle = $row['Title']; echo $jobtitle; ?></font></td>
</tr>
<tr>
<td class="mainboldfont"> </td>
<td class="mainboldfont"> </td>
</tr>
<tr>
<td class="mainboldfont" width="45%"><font color="#000099">YOUR Name</font></td>
<td class="mainboldfont" width="55%"><font color="#000099">YOUR Email Address</font></td>
</tr>
<tr>
<td width="45%"><input type="text" name="namefrom" size="28" value=""></td>
<td width="55%"><input type="text" name="emailfrom" size="28"></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="mainboldfont" width="50%"><font color="#000099">FRIEND'S Name</font></td>
<td class="mainboldfont" width="50%"><font color="#000099">FRIEND'S Email Address</font></td>
</tr>
<tr>
<td width="50%"><input type="text" name="nameto1" value="" size="28"></td>
<td width="50%"><input type="text" name="addrto1" value="" size="28"></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="mainboldfont"><font color="#000099">Add a personal message <font class="mainfont"><font color="#000099">(optional)</font></font></td>
</tr>
<tr>
<td>
<textarea cols="48" rows="4" name="note" wrap="hard"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value=" SEND " name="send" id="send">
<input type="button" value=" CANCEL " name="cancel" id="cancel">
</td>
</tr>
</table>
<!-- END: form -->
<!-- BEGIN: Footer Table -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="mainfont"><font color="#000099">
The information entered above will only be used to email this
<br>page on your behalf and will not be used for any other purpose.
</font></td>
</tr>
</table>
<!-- END: Footer Table -->
</td>
<td bgcolor="#ffffff"><img src="/roving/images/spacer.gif" alt="" width="1" height="1" border="0"></td>
</tr>
<tr>
<td bgcolor="#ffffff" colspan="2"><img src="/roving/images/spacer.gif" alt="" width="1" height="1" border="0"></td>
<td valign="bottom"> </td>
</tr>
</table>
<!-- END: Main Content Table -->
<div align="left">
<!-- BEGIN: Close Table -->
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="bottom"><img src="/roving/images/bl_trans_reversed.gif" alt="" width="15" height="30" border="0"></td>
<td bgcolor="#ffffff" class="headerfont" NOWRAP><a href="" class="nodecoration" onClick="window.close(); return false;"><font color="#000099">X Close</font></a></td>
<td valign="bottom"><img src="/roving/images/br_trans_reversed.gif" alt="" width="15" height="30" border="0"></td>
</tr>
</table>
<!-- END: Close Table -->
</div>
</td>
</tr>
</table>
</form>
<?php
} //end while statement
} // end function sendform()
switch ($HTTP_GET_VARS['goto']) {
case 'mail':
if ($namefrom <= "") {
$warning = "Please go back and enter your name.<BR><BR>";
}
else if ($emailfrom <= "") {
$warning = "Please go back and enter your email.<BR><BR>";
}
else if ($nameto1 <= "" || $addrto1 <= "") {
$warning = "Please enter at least one friend's name and email.<BR><BR>";
}
if ($warning) {// If we've set a message with a warning about their form entry...
$status = "not_ok";
?>
<table width="400" border="0" cellspacing="2" cellpadding="2">
<table width="">
<tr><td>
<?php echo $warning; ?>
</td></tr>
<tr>
<td>
<A HREF="javascript:back()"> <img src="../images/buttons/button_back.gif" alt="Back" width="55" height="18" border="0"> </A> </td>
</tr>
</table>
<?
} // end if($warning)
if (!$warning) {
$status = "ok";
// Read POST request params into global vars
$id = $_POST['jobid'];
$to = $_POST['addrto1'];
$subject = "Job Referral from ". $_POST['namefrom'] .": " . $jobtitle . "";
$namefrom = $_POST['namefrom'];
$emailfrom = $_POST['emailfrom'];
$note = $_POST['note'];
$headers = "From: $emailfrom";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "Name of sender: " . $namefrom . "\n" .
"Email: " . $emailfrom . "\n" .
"Additional Info: " . $note . "\n\n" .
"Job Title: ". $jobtitle ."\n" .
"Location \n" .
"Duration \n" .
"Positions Available: \n" .
"Required Skills: \n" .
"Preferred Skills: \n" .
"Misc: \n" .
"Link: ". $link ."\n\n";
;
// Send the message
if ($status == "ok") {
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<B><font size=3>Your mail was sent to the following.</font></B><BR>";
echo "<p>(Put data here)</p>";
} else {
echo "<B><font size=3>Mail Error</font></B><BR>";
echo "<p>Your mail could not be sent.</p>";
} //end !$warning if statement
}
} // end if(!warning)
break;
default:
$goto = '';
sendform();
}
//end SWITCH statement
?>
</body>
</html>