/    Sign up×
Community /Pin to ProfileBookmark

send email through contact form to email stored in database

Hey guys, I’m new here so go easy on me.

I’ve currently got a form that sends text messages to my cell phone and to my regular email address. it’s at an address like…
[url]http://www.domain.com/contactform.html[/url]

It then sends it via a page located at…
[url]http://www.domain.com/contactform.php[/url]

what I would like to do is set up the contact form in such a way that it would be at a domain like…
[url]http://www.domain.com/contactform.php?id=17[/url]

where if someone fills out the form and pushes send it would send it to an email address defined as “17” I’d like to set it up so I can continue to define different email addresses for different ID#’s. so when you go to …form.php?id=25 it would send to the email address(s) defined as ID # 25.
(this way the form can send to different email addresses as defined by the ID number in the URL.)

How would I go about setting this up?

is a database the best way? what other options do I have?
I’m not very skilled but I understand the basics of php.

Thanks in advance.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderOct 12.2007 — At the top of your contactform.php file

[code=php]
$email_addresses = array("1" => "[email protected]", "2" => "[email protected]");

if(isset($_GET["id"]) && array_key_exists($_GET["id"], $email_addresses))
{
$to_address = $email_addresses[$_GET["id"]];
} else {
$to_address = "[email protected]";
}
[/code]


Then just edit the array as required and use to_address.

If you want to use a database will you be using mysql?
Copy linkTweet thisAlerts:
@maxaudauthorOct 12.2007 — I'd be using mysql.

I'd like to have on the page a unique picture for each ID as well, how would this be obtained?

How would I set up the contact form on contactform.php?

my current contact form reads like this (contactform.html)...

[CODE]<HTML><HEAD><TITLE>Send me a text message!</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2180" name=GENERATOR>

<STYLE>BODY {
COLOR: #373737; FONT-FAMILY: Verdana, sans-serif
}
TD {
FONT-SIZE: 11px
}
#warning {
DISPLAY: none
}
</STYLE>

<SCRIPT type=text/javascript>
var totalchars = 100;

function countChars()
{
// getting the remaining characters (will also count line beaks!)
charNum = totalchars - (document.textmeform.txtName.value.length + document.textmeform.txtNumber.value.length + document.textmeform.txtMessage.value.length)

//dumping the number in your input box
document.textmeform.characters.value = charNum

if ( charNum <= 0 )
{
document.textmeform.characters.style.background = "#FF9966";
document.getElementById("warning").style.display = "block";
}
else
{
document.textmeform.characters.style.background = "#FFFFFF";
document.getElementById("warning").style.display = "none";
}
}
</SCRIPT>
</HEAD>
<BODY onkeydown=countChars() onkeyup=countChars()>
<center>
<FORM name=textmeform action=TextMe.php method=post>
<BR><STRONG>Please use the form below to
send a short text message to my cell phone.</STRONG><BR>a duplicate will also be sent to my email.<BR>&nbsp;

<TABLE width="100%" align=center border=0>
<TBODY>
<TR>
<TD align="center">&nbsp;
<TABLE border="1" cellpadding="6" cellspacing="0" bordercolor="#999999" bgcolor="#F5F5F5">
<TBODY><img src="http://www.domain.com/picture_of_me.jpg"><br />
<TR>
<TD>
<P align=right>Your Name:</P></TD>
<TD>
<P align=left><INPUT onkeydown=countChars() onkeyup=countChars()
onchange=countChars() name=txtName></P></TD></TR>
<TR>
<TD>
<P align=right>Your Phone Number&nbsp;</P></TD>
<TD><INPUT onkeydown=countChars() onkeyup=countChars()
onchange=countChars() name=txtNumber></TD></TR>
<TR>
<TD align=right>Your Email Address&nbsp;</TD>
<TD><INPUT name=txtEmail></TD></TR>
<TR>
<TD align=right>Your Message&nbsp;</TD>
<TD><TEXTAREA onkeydown=countChars() onkeyup=countChars() name=txtMessage onchange=countChars()></TEXTAREA></TD></TR>
<TR>
<TD align=right>&nbsp;</TD>
<TD><INPUT type=submit value="Send Message" name=Button1></TD></TR>
<TR>
<TD align=right>Characters Remaining:</TD>
<TD><INPUT id=characters size=3 value=100
name=characters></TD></TR></TBODY></TABLE><BR>
<DIV id=warning>You have more than 100 characters! <BR>Your message may be
truncated. </DIV></TD>
</TR></TBODY></TABLE>
</FORM></FONT>
</center>
</BODY></HTML>[/CODE]


where my current php code is...

[CODE]<?php

$to="[email protected]";

$from="{$_POST['txtEmail']}";

$sucessURL="http://www.domain.com/success_url.html";

$failureURL="http://www.domain.com/failure_url.html";

$subject="subject line";

$msg = "nFrom: {$_POST['txtName']}nP: {$_POST['txtNumber']}nE: {$_POST['txtEmail']}nMessage: ".nl2br($_POST['txtMessage'])."
";

$headers = "Reply-To: {$_POST['txtEmail']}rn";
$headers = "From: {$_POST['txtName']} <{$from}>rn";
$header .= "X-Priority: 1";

if(mail($to, $subject, $msg, $headers, "-f{$_POST['txtEmail']}"))
{
header("Location: $sucessURL");
}
else
{
header("Location: $failureURL");
}
?>[/CODE]
×

Success!

Help @maxaud spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...