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 = "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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.