|
-
Sep 19th, 2006, 06:25 AM
#1
Thread Starter
Member
[RESOLVED] Forms
Is it possible for someone to lend me a hand writing a basic form in php? (I've looked at the free scripts and they aren't pretty)
I'm looking to have a general form asking the usual information form a prospective member, nothing fancy. Instead of storing information on a table, All I want to have happen is the information dumped into an email and sent to recipients of my choosing.
Once it's emailed, the data will, in theory, no longed exist anywhere except in that email but I'm ok with this.
I've been working out of the php books but I have problems with the submit button generating the email for outlook express and sending it off. I would even be happy if it returned the content as a document that the end user had to dump in an email (because no 2 people ever use the same email client)
I'm out on a limb here, probably biting off more than I can chew but would appreciate any help that can be offered.
Last edited by Albatross; Oct 11th, 2006 at 09:24 AM.
-
Sep 19th, 2006, 10:18 AM
#2
Junior Member
Re: Forms
Hi Albatross...
here's the code for a simple form that sends
whatever you type to the email you specify..
it's the simplest one I got hope it's what you're
lookin for...
here's the first file. this is the form page code in full:
--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<div align="right"></div>
<table width="550" border="0" align="center" cellpadding="10">
<tr>
<td height="565" align="center" valign="top">
<div align="left">
</p>
</div> <div align="left">
<table width="312" border="0" align="center" cellpadding="10">
<tr>
<td width="288"><p align="left"><font face="Verdana, Arial, Helvetica, sans-serif"><font color="#000033">Subject
:</font><font color="#000033"><br>
</font>
<input name="subject" type="text" id="subject" size="35" maxlength="60">
</font></p>
<form name="form1" method="post" action="NAMEofOtherPage.php">
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif"><font color="#000033">Message:</font><font color="#000033"><br>
</font></font>
<textarea name="message" cols="33" rows="6" id="message"></textarea>
</p>
<p align="left"><font color="#000033" face="Verdana, Arial, Helvetica, sans-serif"> Email:</font> <br>
<font face="Verdana, Arial, Helvetica, sans-serif">
<font color="#006699">
<input name="email" type="text" id="email" size="35" maxlength="60">
</font></font></p>
<table width="200" border="0">
<tr>
<td><font color="#000033" size="1" face="Verdana, Arial, Helvetica, sans-serif">Please
include your e-mail address if you would like to be notified
when our new website is launched. </font></td>
</tr>
</table>
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Send Message">
<input type="reset" name="Submit2" value="Reset">
</font></p>
</form> <div align="right">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div></td>
</tr>
</table>
</div>
<div align="center"></div>
<p align="left"> </p> </td>
</tr>
</table>
<p> </p>
</body>
</html>
-----------------------
and here's the page that does all the dirty work for u...[this page is called when u click submit] it's specified in the form action..above.
Name it NAMEofOtherPage.php
----------------------
<?
$email=@($_POST['email']);
$subject=@($_POST['subject']);
$mailto="[email protected]";
$message=@($_POST['message']);
$mysubject="Online Form Submission";
$mail = 'Here is your online mail submission:
<p>
Subject: '.$subject.'<p>
Message: '.$message.'<p>
E-mail Address: '.$email;
$header* = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$header .= "From: [email protected]";
if (empty($message)){
echo '<html>
<head>
<title>Form Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" >
<div align="right"></div>
<p> </p>
<table width="550" border="0" align="center" cellpadding="10" background="bg1.jpg">
<tr>
<td >
<p align="right"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#FFF0D1">
</font></font></font></font></font></p>
<p align="center"><font color="#000033" size="3" face="Verdana, Arial, Helvetica, sans-serif">The form was not sent. Please write a message.</font></p>
<p align="center"> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>';
}else{
mail($mailto, $mysubject, $mail, $header);
echo'<html>
<head>
<title>Form Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" >
<div align="right"></div>
<p> </p>
<table width="550" border="0" align="center" cellpadding="10" background="bg1.jpg">
<tr>
<td >
<p align="right"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#99FFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><font color="#FFF0D1">
</font></font></font></font></font></p>
<p align="center"><font color="#000033" size="3" face="Verdana, Arial, Helvetica, sans-serif">Thank
you for your submission.</font></p>
<p align="center"> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>';
}
?>
------------------
Hope you find it useful..
-
Sep 19th, 2006, 07:50 PM
#3
Thread Starter
Member
Re: Forms
Wow....when you provide help, you provide HELP! tytytytytytytytytytytyty
(did I mention, thank you )
Trying this tonight so here's hoping it works for me!
-
Sep 20th, 2006, 01:27 AM
#4
Re: Forms
Please use the [code]code here[/code] tags.
-
Sep 20th, 2006, 06:19 AM
#5
Thread Starter
Member
Re: Forms
Ok, Jackpot. It worked perfectly, and sends me a nice little email.
Second part of this, right now, in the contents of the email, you get a few of the header items and the main message.
I've added fields to the input page. Can you educate me on how to tell the script to grab those and include them as well in the email?
-
Sep 22nd, 2006, 02:20 AM
#6
Junior Member
Re: Forms
Hi there..glad to be of help..
To add more input info to the email just..declare the variable
at the beginning of the second page with all the others..(see
below) according to your input field in the first page..
Then just add the variable to the $mail content...(shown below)
Code:
<?
$inputfield=@($_POST['inputfieldname']);
$email=@($_POST['email']);
$subject=@($_POST['subject']);
$mailto="[email protected]";
$message=@($_POST['message']);
$mysubject="Online Form Submission";
$mail = 'Here is your online mail submission:
<p>
Subject: '.$subject.'<p>
Message: '.$message.'<p>
Other Input: '.$inputfield.'<p>
E-mail Address: '.$email;
$header* = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$header .= "From: [email protected]";
Hope this is what u meant wasn't quite sure
-
Oct 5th, 2006, 10:54 AM
#7
Thread Starter
Member
Re: Forms
My apologies for the late response....been bustin arse at work and hadn't had a huge heap of time to get this tested. In short...it worked perfectly.
Hypothetically speaking, would it be difficult to redirect my line of thinking and have the supplied information sent to a mySQL table? The form to pull it up I can do easily enough...but getting the data sent there is the fun part.
*Initial request is MORE than resolved. Leaving header untagged for one more reply *
-
Oct 5th, 2006, 03:16 PM
#8
Re: Forms
do you know how to make a MySQL table already, and do you have it set up/etc?
If so, you can easily run a quick query to insert that data into the table.
For example, using the variables above, and assuming you're still using a POST form to submit the data on a form:
PHP Code:
<!-- header -->
<?php
if(isset($_POST['email'], $_POST['subject'], $_POST['message'], $_POST['otherfield'])){
//data has been submitted, you can always do error checking here to check if the messages were blank and stuff, but i'll leave that up to you..
$email = $_POST['email'];
$subject = $_POST['subject'];
$mailto = "[email protected]";
$message = $_POST['message'];
$someotherfield = $_POST['otherfield'];
//etc
//build a query
$query = "INSERT INTO tablename (email, subject, mailto, message, otherfield, date) VALUES ('$email', '$subject', '$mailto', '$message', '$someotherfield', " . time() . ")";
//now, just execute the query
mysql_query($query) or die(mysql_error());
}else{
//data has not been submitted yet, so print the form
?>
<!-- put your form here -->
<? } ?>
<!-- footer-->
-
Oct 11th, 2006, 09:14 AM
#9
Thread Starter
Member
Re: Forms
Thank you very much. I'll give this a whack when I get home tonight and see how it goes.
Yes, adding tables is no problem.
The entire reason for this was to bypass webforms and the monstrosity they presented. I've been able to get a serious amount of real information back from these forms because people spend more time entering it in that trying to figure out what the heck im asking for. My goal for adding to a table is to provide an alternate means of data retrieval, even when not at my regular workstation.
Thank you to everyone who helped me on this !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|