sending e-mail from INSERT DATA php file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
monkeynme
Forum Commoner
Posts: 28
Joined: Thu Aug 14, 2003 3:18 pm
Location: Colorado Springs, CO

sending e-mail from INSERT DATA php file

Post by monkeynme »

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:

Code: Select all

<?PHP>
$LastName = $HTTP_POST_VARS&#1111;'candLastName'];
$Address = $HTTP_POST_VARS&#1111;'candCity'];
$jobType = $HTTP_POST_VARS&#1111;'jobType'];
$jobID = $HTTP_POST_VARS&#1111;'jobID']

$formsent = mail('dawn@example.com', 'New resume submitted', "The following candidate has submitted a resume: $LastName : $Address : $jobType : $jobID", "From: Company job board."
?>
Here is the existing code that inserts the data into a database:

Code: Select all

$editFormAction = $HTTP_SERVER_VARS&#1111;'PHP_SELF'];
if (isset($HTTP_SERVER_VARS&#1111;'QUERY_STRING'])) &#123;
  $editFormAction .= "?" . $HTTP_SERVER_VARS&#1111;'QUERY_STRING'];
&#125;

if ((isset($HTTP_POST_VARS&#1111;"MM_insert"])) && ($HTTP_POST_VARS&#1111;"MM_insert"] == "form1")) &#123;
  $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&#1111;'candFirstName'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candLastName'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candAddress'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candCity'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candState'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candZip'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candPhone'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candFax'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candEmail'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'jobType'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'coverLetter'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candResume'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'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&#1111;'QUERY_STRING'])) &#123;
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS&#1111;'QUERY_STRING'];
  &#125;
  header(sprintf("Location: %s", $insertGoTo));
&#125;
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can add your email sending code into your form handling page - if you like you could put it just above the header() call.

Mac
Post Reply