Calling a variable in database using a form to email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
canalcasting
Forum Newbie
Posts: 1
Joined: Mon Mar 09, 2009 7:03 am

Calling a variable in database using a form to email

Post by canalcasting »

Hello everyone..

I am kinda new to this.. well let's say I have been trying to work on php in the last few months and that's not an easy thing...

I am running into some issue and I have no clue what to do...

I have a database where table members has field " name " and email

I have created a form , where I query all emails in table and it sends out an email correctly.

The form has 3 input, for email, subject and a text area where I write the message. It does work correctly but what I can't get it to work and to call the variable $name from the database right inside the text area.

If I write L

Hello everyone blah blah blah .. it sends out correctly... but if I try :
Hello $name , It sends out Hello $name , and not the actual name..

I have tried

hello <? echo $name ?>
Hello $name
Hello <? $name ?>
Hello $row[name]
Hello $row['name']

It just seems, that being n a form I am missing something. I remember seeing somewhere using slash " / " before or after , or even /* somewhere.. Just can't be sure.. anyway I have spend hours on this and I am going nuts..
Thanks for any advice

Here is the code :

<?php
$sitename = '#######'; // The name you want to appear in the email
$siteemail = '#######'; // The email address for email replies

$hostname = '#######'; // Your mysql hostname, usually localhost
$username = '#######'; // Your mysql username, e.g root
$password = '#######'; // Your mysql password
$database = '#######'; // Your mysql database, e.g loginscript


mysql_connect("$hostname", "$username", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());


if (isset($_POST['submit'])) {
$tabla = mysql_query("SELECT * FROM newsletter2 WHERE status='active'");
while ($row = mysql_fetch_array($tabla)){
$email = $row['email'];
$subject = $_POST['subject'];
$name = $_GET['name'];
$messagetext = "".$_POST['emailmessage']."";
$siteadmin = "From: " . $sitename . " < " . $siteemail . " >";
mail($email, $subject, $messagetext, $siteadmin);
}
echo 'Email sent!';
}else{
?>
<form action="email4.php" method="post">
<fieldset>
<legend>Send Email</legend>
<table border="0">
<tr><td>Subject:</td>
<td><input type="text" name="subject" size="33" maxlength="255"></td></tr>
<tr><td>Message:</td>
<td><textarea name="emailmessage" rows="6" cols="30"></textarea></td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Send Email"></th></tr>
</table>
</form>
</fieldset>
<?php } ?>
Post Reply