View Full Version : Mail from Database

06-27-2007, 05:12 PM

Can someone please help here,

I have a form where you have to enter a name that has been insterted into the DB.

The script I use is called mymail.php, You make a contact form and it correct everything and send it out.

I just want to make it so when you enter a name it takes the e-mail address from mysql and put it in at the e-mail section.

My details
mysql = db = gomail table = users rows are "first" and "mail"

Here is my mail script I just need to get the mail in the correct area on you typed in a mail.



<form action="mymail.php" method="post">
<br />
<table width="391" border="0" cellpadding="2" cellspacing="2">
<td width="84" height="37">name</td>
<td width="291"><input name="name" type="text" id="name" /></td>
<td height="35"><span class="style4">email</span></td>
<td><input name="email" type="text" id="email" /></td>
<td height="47"><span class="style4">Description:</span></td>
<td><p class="style4">
<textarea name="comments" id="comments"></textarea>
<p class="style4">
<input name="first" type="text" id="first" />
<td><span class="style4"></span></td>
<td><input name="submit" type="submit" /></td>


$first = $_POST['first'];

$con = mysql_connect("localhost","**USERNAME***","****mypass***");
if (!$con)
die('Could not connect: ' . mysql_error());

@mysql_select_db("gptesting_co_za_-_gomail") or die( "Unable to select database");
$query="SELECT * FROM users WHERE first='$first'";



# You can use this script to submit your forms or to receive orders by email.
$MailToAddress = "$mail"; // your email address
$redirectURL = "http://www.test.co.za"; // the URL of the thank you page.
$MailSubject = "Form"; // the subject of the email
$sendHTML = FALSE; //set to "false" to receive Plain TEXT e-mail
$serverCheck = TRUE; // if, for some reason you can't send e-mails, set this to "false"

//////I did not copied the rest of the script has it has no use....

06-27-2007, 05:16 PM
What are you trying to do?


Where is $i being set?

06-27-2007, 05:29 PM
I am trying to make the script see that if it gets a first name it must supply the e-mail address and add it into mail.

$MailToAddress = "$mail"; // your email address

06-27-2007, 07:43 PM
i believe you want a mail merge?
SELECT first, mail FROM mail_table
while ($row = mysql_fetch_array($query)) {
//send mail to $row['mail'];
//body Hello $row['first'];

06-28-2007, 09:23 AM
thanks... :thumbsup: