PDA

View Full Version : Passing a variable from textarea to email


Ted Varnson
08-08-2005, 08:22 PM
I'm trying to set up a mailing list. I've pretty much got everything working. I just need help finishing it up. I want to be able to include things such as $name and other personal information that the user enters in when htye sign up. I am having a problem getting the variable to parse. I think I have everything set up correctly (obviously something is wrong since it working!). What is happening with my script is that it is displaying as $name in the email rather than what the name is in the database.

I am using PHP and MySQL. Here is my form code

<form method="post" action="index.php?action=mailinglistsend2">
<table border="0" cellpadding="3" cellspacing="1" width="100%" class="normalfont">
<tr>
<td class="gradient">
<b>Mailing List</b>
</td></tr>
<tr>
<td>
Send message to:<br />
<select name="to" size="1">
<option selected value="all">Entire list</option>
</select>
</td>
</tr><tr>
<td class="alt2">
Subject: <br /><input name="subject" type="text" maxlength="100" size="40">
</td></tr><tr><td>
Message:<br />
<textarea wrap name="message" rows="10">
$name,



</textarea>
</td></tr><tr><td class="header"><div align="center">
<input type="submit" name="submit" value="Send"></div>
</td>
</tr>
</table>
</form>

here is my parsing code
$to = $_POST['to'];
$subject = "" . $Settings['sitename']. ": " . $_POST['subject']. "";

$x = 1;
$hold = 50; // quantity of emails sent before 3 sec delay
$emails = mysql_query("SELECT * FROM test");
while ($sendemail = mysql_fetch_array($emails)) {
$name = $sendemail["name"];
$email = $sendemail["email"];
$message = "" . $_POST['message'] . "" . $spam ."";
mail($email, $subject, $message, "From: ". $Settings['sitename'] . " <email@email.com>");
$x++;
if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
sleep(3);
$x = 0;
}
}

Any help would be appreciated. Thanks a lot!

raf
08-08-2005, 08:52 PM
looks more like a PHP question to me + i don't see you use $name anywhere in your while-loop. So i can only assume that you are sending the '$name' from your textarea.

if you want to replace that $name, then use

$message = str_replace('$name', $name, $_POST['message']) . $spam;

Ted Varnson
08-08-2005, 11:15 PM
Thanks raf, you are always so helpful.

raf
08-08-2005, 11:34 PM
You're welcome!