sending e-mail from INSERT DATA php file
Posted: Tue Nov 11, 2003 12:50 pm
I have a file which inserts job candidate data into a database. When an entry is made, it should notify HR that a new candidate has been submitted and provide basic info: name, address, job type, job ID. The form that's created has an action called "<?php echo $editFormAction; ?>". Can I place a mail() code within the same file which uses the data captured to send an e-mail? In other words can I just put this code somewhere in my existing file, or does the FORM ACTION need to point to a separate file with both database insertion and mail capabilities:
Here is the existing code that inserts the data into a database:
Code: Select all
<?PHP>
$LastName = $HTTP_POST_VARSї'candLastName'];
$Address = $HTTP_POST_VARSї'candCity'];
$jobType = $HTTP_POST_VARSї'jobType'];
$jobID = $HTTP_POST_VARSї'jobID']
$formsent = mail('dawn@example.com', 'New resume submitted', "The following candidate has submitted a resume: $LastName : $Address : $jobType : $jobID", "From: Company job board."
?>Code: Select all
$editFormAction = $HTTP_SERVER_VARSї'PHP_SELF'];
if (isset($HTTP_SERVER_VARSї'QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARSї'QUERY_STRING'];
}
if ((isset($HTTP_POST_VARSї"MM_insert"])) && ($HTTP_POST_VARSї"MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO candidates (candFirstName, candLastName, candAddress, candCity, candState, candZip, candPhone, candFax, candEmail, jobType, coverLetter, candResume, jobID) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARSї'candFirstName'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candLastName'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candAddress'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candCity'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candState'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candZip'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candPhone'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candFax'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candEmail'], "text"),
GetSQLValueString($HTTP_POST_VARSї'jobType'], "text"),
GetSQLValueString($HTTP_POST_VARSї'coverLetter'], "text"),
GetSQLValueString($HTTP_POST_VARSї'candResume'], "text"),
GetSQLValueString($HTTP_POST_VARSї'jobID'], "int"));
mysql_select_db($database_EagleMain, $EagleMain);
$Result1 = mysql_query($insertSQL, $EagleMain) or die('<p>All fields must be completed!<br>'.
'Error: ' . mysql_error() . '</p>');
$insertGoTo = "thankyou.htm";
if (isset($HTTP_SERVER_VARSї'QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARSї'QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}