View Full Version : PHP Form: Sending to a different email addy
ctdesign87
June 12th, 2005, 12:19 PM
Hey there
I've read the PHP Form tutorials on this site, and with no prior PHP skills, I found it hard to 'mix' the information with what I required. I need to be able to create a form so the user can select which email he/she wants to send the msg to.
So therefore, I'll need a Name field, a Dropdown box (with the emails for the user to select) and also a Comments field. With the dd box, it would be preferable if only one email could be selected.
any feedback is appreciated
thanks
Enigmatic
June 12th, 2005, 01:33 PM
How about something like:
<?php
if(isset($_POST['contact']))
{
$name = strip_tags($_POST['name'], '');
$email = strip_tags($_POST['email'], '');
$subject = strip_tags($_POST['subject'], '');
$message = strip_tags($_POST['message'], '');
$to = ['sendTo'];
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
mail($to, $subject, $message, $headers);
echo "";
header("Refresh:5; URL = http://www.your_domain.com/thankyou.php");
exit;
}
?>
<HTML>
<HEAD>
<TITLE>Contact me</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function checkForm()
{
var gname, gemail, gsubject, gmessage;
with(window.document.contactform)
{
gname = name;
gemail = email;
gsubject = subject;
gmessage = message;
}
if(gname.value == '')
{
alert('Please enter your name!');
gname.focus;
return false;
}
if(gemail.value == '')
{
alert('Please enter your email!');
gemail.focus;
return false;
}
if(gsubject.value == '')
{
alert('Please enter subject!');
gsubject.focus;
return false;
}
else if(gmessage.value == '')
{
alert('Enter your message!');
gmessage.focus;
return false;
}
else
{
return true;
}
}
</script>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<DIV ALIGN=CENTER>
<table align="center" border="0" width="557" cellpadding="5" cellspacing="2">
<tr>
<td width="499" align="center" valign="middle">
<form name="contactform" action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post" onSubmit="return checkForm();">
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td width="69" align="right" class="style3">Your Name:</td>
<td width="410" valign="middle"><input name="name" type="text" class="input_box2" size="30" ></td>
</tr>
<tr>
<td align="right" valign="middle" class="style3">Your Email:</td>
<td><input name="email" type="text" class="input_box2" size="30" ></td>
</tr>
<tr>
<td align="right" valign="middle" class="style3">Subject:</td>
<td><input name="subject" type="text" class="input_box2" size="30" ></td>
</tr>
<tr>
<td align="right" valign="middle" class="style3">Send to: </td>
<td><select name="sendTo">
<option value="email_address1" selected>Email Address 1</option>
<option value="email_address2">Email Address 2</option>
<option value="email_address3">Email Address 3</option>
</select></td>
</tr>
<tr>
<td align="right" valign="top" class="style3">Message:</td>
<td><textarea name="message" cols="55" class="multiline_box"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="contact" type="submit" class="button2" value="Send">
<input name="Reset" type="reset" class="button2" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</DIV>
</BODY>
</HTML>
ctdesign87
June 13th, 2005, 03:36 AM
hey ther
thanks for ur help, however im still having some difficulty. am i supposed to save that whole file as a php document, and then just slap it into my server directory?
also, if i am, im still having trouble with some of the parsing. it indicates theres an error on line 9. am i supposed to change any of the information inside of the php code that youve given me?
i hope this is correct:
<select name="sendTo">
<option value="email1@email.com" selected>Joe Bloggs</option>
<option value="email2@email.com">Kirupa</option>
<option value="email3@email.com">Bla Bla</option>
plz tell me if any of its wrongly formatted. sorry, im just all over the place. any feedback would be greatly appreciated.
Enigmatic
June 13th, 2005, 06:05 PM
Sorry dude, my bad, missed some code out.
Line 9 error correction:
##FIND##
$to = ['sendTo'];
##REPLACE WITH##
$to = trim($_POST['sendTo'], '');
You could replace TRIM with STRIP_TAGS if you prefer, TRIM removes white space before and after the variable.
ctdesign87
June 13th, 2005, 09:31 PM
that did work wonders
thanks for ur help there!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.