PHP Mail Help

I am trying to send 2 emails when a user inputs their own unique code into a html form and submits. One email will come to me and the other will go to them. The unique code they enter will pull the email address from a sql database.

I so far I can get an email to sent to ME containing the users info in my message, but it will not send an email to the user (email value that was pulled from SQL)

Below I have the PHP code I have, everything works apart from the php mail to user (bottom of the code). Sugestions would be a great help! Many Thanks in advance :slight_smile:


<?php mysql_connect ("localhost", "DB","PASSWORD") or die (mysql_error()); mysql_select_db ("TABLE"); $ID = $_POST['ID']; $query = mysql_query("SELECT * FROM `users` WHERE ref LIKE $ID "); while ($row = mysql_fetch_array($query)){ $fname = $row['fname']; $sname = $row['sname']; $email = $row['email']; $ref = $row['id']; } $user=mysql_num_rows($query); if ($user == 0) { echo '
Invalid reference number, please go back and try again!

'; ?> <?php $to = ''; $subject = 'Registered User Request'; $headers = "From: noreply@mydomain\r\n" ; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message = ''; $message .= '

User expressed interest!

' $message .= 'info for me to go here'; $message .= ''; mail($to, $subject, $message, $headers); echo '1st Mail sent '; ?>

// This is the email that I want to send to the User. However the email will not send to the value from the sql database

<? $from = $email ; $subject2 = 'Auto-Reply'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "From:\r\n" ; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $autoreply = ''; $autoreply .= 'Thank you!!!'; $autoreply .= ""; mail( $from , $subject2, $autoreply, $headers); echo 'Mail sent!!!' ?>