First of all, you need to change your SQL query because you do not need two equation signs
Change query to look like this:
Code: Select all
$email = "SELECT email FROM employees WHERE last_name = '$_POST[employee]'";
Then, you need to make array or object out of $to variable because, what mysql_query function returns is resource, so you need use fetch function to get what you need from that resource. I am preffering to use mysql_fetch_object() function to do that.
Now, to do that, add this piece of code just before mail function:
Code: Select all
$to = mysql_fetch_object( $email );
$to = $to -> email;
So, your code finaly should look like this:
Code: Select all
$email = "SELECT email FROM employees WHERE last_name = '$_POST[employee]'";
$to = mysql_query($email,$con);
$newStart = date('l, F jS', strtotime($_POST[start]));
$newEnd = date('l, F jS', strtotime($_POST[end]));
$subject = "$_POST[employee] Requested Coverage";
$message = "$_POST[employee] has requested off from $newStart to $newEnd.\n\nThis message has been sent automatically.";
$from = "DJ System <xxx@xxx.com>";
$headers = "From: $from";
$to = mysql_fetch_object( $to );
$to = $to -> email;
mail($to,$from,$subject,$message,$headers)
Cheers!