Jump to content

[SOLVED] can't send dynamically


contra10

Recommended Posts

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 = "[email protected]";
$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 = "[email protected]";
$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 = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$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

Link to comment
https://forums.phpfreaks.com/topic/146304-solved-cant-send-dynamically/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.