-
Newsletter Form
Hi all,
Just wondering if someone could assist me with the following issue. I have a web form which simply consists of the folowing:
HTML Code:
<form action="" class="newsletter">
<strong>Enter your email</strong><br />
to receive our latest news and proposals
<div>
<inout type="text" value="" /><a href="#"><img alt"" src="images/button_sign_up.gif" /></a>
</div>
</form>
What I wanted to do was send the submitted form to an email address and a database.
I cobbled the following together for the database:
PHP Code:
function add_to_db($data){
$link = mysql_connect("localhost", "username", "password") or die("Could not connect: " . mysql_error());
mysql_select_db("dbname", $link) or die ('Can\'t use this DB : ' . mysql_error());
$values = '';
$flds = '';
foreach ($data as $f => $val){
$values .= (empty($values) ? "'".$val."'" : ",'".$val."'");
$flds .= (empty($flds) ? $f : ','.$f);
}
$sql = "INSERT INTO contact ({$flds}) VALUES({$values})";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
mysql_close($link);
}
However, I'm not sure of where or how to add the email function for this so it send the submitted form to an email account as well as the database.
Any help much appreciated.
-
Re: Newsletter Form
just call your add_to_db() function in conjunction with a call to mail() to send the email.