contra10 Posted February 22, 2009 Share Posted February 22, 2009 I'm trying to send an email dynamically based on what is has been put in the database i've tried this <?php $f= "SELECT * FROM `users` WHERE `username` = '$usernamef'"; $fr = mysql_query($f) or die(mysql_error()); while ($fri = mysql_fetch_assoc($fr)) { $email = "{$fri['email']}"; } $to = "$email"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); ?> and i've even tried to pull it from the form <?php while ($fri = mysql_fetch_assoc($fr)) { $emailed = "{$fri['email']}"; } $email = $_REQUEST['email'] ; $to = $fri['email']; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($email,$subject,$message,$headers); ?> <h6>A request has been sent</h6> <p>Thank you<?php "<a href= 'http://localhost/friendrequest/index.php?user='</a>Main"?></p> <?php } else { ?> <?php echo"$email";?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="500" align="center" height="100"> <tr> <td align="right"><?php echo "<input type='hidden' name='requestid' value='$useridf'>";?></td></tr> <td align="right"><?php echo "<input type='hidden' name='requestname' value='$usernamef'>";?></td></tr> <td align="right"><?php echo "<input type='hidden' name='email' value='$emailed'>";?></td></tr> <td align="right"><input type="submit" name="add" value="Add Friend"></td></tr> </table> </form> ?> neither worked however if i did this <?php $to = "me@something.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); ?> it would work...i've noticed that when i put a variable in place of $to that is being drawn from the db it doesn't work...it only works when i actually write in the email...but the code is suppost to be dynamic and reflective of the user logged in my question is how to i make the $to reflect the person who i'm sending to Quote Link to comment Share on other sites More sharing options...
contra10 Posted February 22, 2009 Author Share Posted February 22, 2009 any websites that can help? Quote Link to comment Share on other sites More sharing options...
dropfaith Posted February 22, 2009 Share Posted February 22, 2009 TRY TO ECHO OUT THE QUERY TO MAKE SURE ITS GETTING THE RESULTS YOU WANT IT To dAmn caps Quote Link to comment Share on other sites More sharing options...
contra10 Posted February 22, 2009 Author Share Posted February 22, 2009 yep the query shows the result i need Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.