View Full Version : .php email form
merdolator
10-15-2002, 11:45 PM
okay... i will try to compress my story and get to the point. :(
i understand that IE6 does not support html forms. i tried this and when i hit the submit button, none of the form elements were passed on to the email once my Outlook Express message opens... so i take on learning .php.
here is my code on the form.html page where users will enter info to be sent to my email address of choice:
________________________________
<style type="text/css">
<!--
.button { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt}
.textarea { font-family: "MS Sans Serif"; font-size: 9pt; width: 195px}
.input { width: 195px}
-->
</style><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Request Information</b></font></td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#FFFFFF" width="200">
<tr>
<td width="149">
<form method="post" action="inquiry.php">
<table border="0" cellspacing="0" cellpadding="2" bgcolor="" align="center">
<tr>
<td class="td1" height="40"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">How can we help?</font></b></td>
</tr>
<tr>
<td class="td1"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Name:</font><br>
<input type="text" name="senders_name" maxlength="25" class="input" size="23">
</td>
</tr>
<tr>
<td class="td1"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">e-mail:</font><br>
<input type="text" name="senders_email" size="23" maxlength="50" class="input">
</td>
</tr>
<tr>
<td class="td1"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Details(*):</font><br>
<font face="MS Sans Serif" size="1">
<textarea name="message" cols="19" wrap="VIRTUAL" rows="6" class="textarea"></textarea>
</font>
</td>
</tr>
<tr valign="top">
<td>
<input type="submit" value="Submit" class="button">
<input type="reset" value="Reset" class="button">
<input type="hidden" name="action" value="add">
<input type="hidden" name="id" value="25">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
and here is the inquiry.php document i tried to script:
____________________________
<?php_track_vers?>
<?php
$msg = "name:\t$senders_name\n";
$msg = "email:\t$senders_email\n";
$msg = "message:\t$message\n\n";
$mailheaders = " contact form\n";
$mailheaders .= "reply to: $senders_email\n\n";
mail("emailaddress@domain.com", "Subject of form", $msg, $mailheaders);
echo "<h1 align=center>Thanks, $senders_name!</h1>";
echo "<p align=center>Your submission has been accepted.</p>";
?>
_______________________________
so...
the form fills out okay by the user...
and the submit button echos the confirmation with a:
- Thanks "$senders_name!" Your submission has been accepted. - :D
and the email shows up at the proper email of choice...
and the format does show int he body of the email users Name, Email they punched in and the Details to their inquiry.
however...
the "From:" field in my email inbox shows as "Nobody"... :eek:
i need to change this to the "senders_name" at the "senders_email" so i have better management of the emails that come thru... instead of having a bunch of emails that say from "Nobody".
i am close... but stuck at 95% complete.
am i missing something or not doing something right?
please help if you have ideas!
sorry for the long post and...... thanks!
i understand that IE6 does not support html forms
Ehm, what do you mean?
BTW, you can post PHP-code between the [ php ] and [ /php ] (without spaces).
merdolator
10-16-2002, 11:23 AM
what do i mean? heck i donno, i just take others input and run with it....
i tried to make an .html form that would carry over user info like name, email, and comment/inquiry to be sent to an email address. what happened was my email client popped open but did not pass thru any info to that email.
so i emailed the htmlgoodies.com people stating that along with my intent/purpose... and the response that i got was:
"date: Mon, 14 Oct 2002
from: Eric Ferguson
subject: Re: HTMLGoodies HTML Mentor Question - passing form information
The problem is version 6 browsers don't support e-mail forms anymore. You could use PHP, Perl or ASP depending upon what your server supports. Contact your web host to find out.
--
Eric Ferguson
Celtic Fringe Web Design
http://www.celticfringe.net
(612)726-6364
"
i am using IE6 and the email mail client was outlook express..... but if this guy's telling my incorrect information, that kinda sucks...
still, y'all'd be proudda me to know i learned what i needed to in .php in about 1 day (2 if you count the debug and rewrite) to do the form. here is my solution:
_______________________________________________
<?php_track_vers?>
<?php
$msg .= "name:\t$senders_name\n";
$msg .= "email:\t$senders_email\n";
$msg .= "message:\t$message\n\n";
$mailheaders .= "from: $senders_email\n";
$mailheaders .= "reply to: $senders_email\n\n";
mail("emailtobedeliveredto@domain.com", "subject of email", $msg, $mailheaders);
echo "<h1 align=center>Thanks, $senders_name!</h1>";
echo "<p align=center>Your submission has been accepted.</p>";
?>
_______________________________________________
now all i have to do is create a dropdown menu in the html doc where the value of what the users selects becomes the subject of the email. cool! :cool: wish me luck.
.php is not to scary to get into at 1st like i had expected, but i bet it will get complex fast.
merdolator
10-16-2002, 11:28 AM
Originally posted by HZR
BTW, you can post PHP-code between the [ php ] and [ /php ] (without spaces).
i JUST got what you meant there. sorry.
<?php_track_vers?>
<?php
$msg .= "name:\t$senders_name\n";
$msg .= "email:\t$senders_email\n";
$msg .= "message:\t$message\n\n";
$mailheaders .= "from: $senders_email\n";
$mailheaders .= "reply to: $senders_email\n\n";
mail("emailtobedeliveredto@domain.com", "subject of email", $msg, $mailheaders);
echo "<h1 align=center>Thanks, $senders_name!</h1>";
echo "<p align=center>Your submission has been accepted.</p>";
?>
duh.
pezland
10-17-2002, 01:06 PM
Try this:
where you have
$mailheaders .= "from: $senders_email\n";
$mailheaders .= "reply to: $senders_email\n\n";
change it to this:
$mailheaders .= "from: $senders_name <$senders_email>\n";
$mailheaders .= "reply-to: $senders_email\n\n";
merdolator
10-17-2002, 02:30 PM
cool, thanks pez.
yeah, i am noticing the ability to move around info into a better organizational pattern and also use that info to dynamicaly create content. i think i need another book.
the one i have (PHP Essentials by Julie C Meloni - was released just before PHP4 was unleashed but makes references to the new standards they have implemented) has obviously helped me enough to get this far and i have read some other chapters as well... but does anyone have suggestions for good textbooks with practical and useful examples. the book i got was 5.99 because it was outdated i guess... but it still works.
______
hey .. another question i have is are you able to use javascript in combination with .php?
for instance... now that i have the form that works for me...
and the .php file echos the confirmation to the sender...
if that form was popped up in a window say 300x300... once they get the .php echo... is there a way to close that window after like say 4 seconds?
i know that if this were just a plain .html page i could do it... but how do i implement this? a frames fage? (should i post this in another forum?)
thanks again.
pezland
10-17-2002, 03:29 PM
Sure you can! Same way as you can use HTML with PHP. I tend to write my mail-send scripts a little bit different, my form action points to $PHP_SELF, which causes the form to send its data to the same page the form itself is on, (but of course you can do it however you like, this is just my javascript/php mix example). I simplified your HTML for readability. Note the slight change to the 'Submit' button, besides the form action, that was the only change to the HTML I made.
rename file to form.php with this example
all code goes into just this one file.
<?php
// When form is submitted, run this script
// Submit button provides the variable
// and value for this IF statement
if ($action == "Submit") {
// Send the email
$msg = "name:\t$senders_name\n";
$msg = "email:\t$senders_email\n";
$msg = "message:\t$message\n\n";
$mailheaders = " contact form\n";
$mailheaders .= "reply to: $senders_email\n\n";
mail("emailaddress@domain.com", "Subject of form", $msg, $mailheaders);
// Pop up confirmation Window
echo "
<script language=\"JavaScript\">
var NewWin=null;
function winClose(){
NewWin = window.open('','success', 'width=300, height=300');
NewWin.document.open();
NewWin.document.write(\"<html><head></head><body><h1 align=center>Thanks, $senders_name!</h1><p align=center>Your submission has been accepted.</p></body></html>\");
NewWin.document.close();
NewWin.focus();
setTimeout('NewWin.close();',5000); /* just wait for 5 seconds */
}
document.onLoad = winClose();
</script>
";
}
?>
<html>
<head>
<title>PHP/Javascript Example</title>
</head>
<body>
<form method="post" action="<?=$PHP_SELF;?>">
<table
<tr>
<td>How can we help?</td>
</tr>
<tr>
<td>Name:<br>
<input type="text" name="senders_name" maxlength="25" class="input" size="23">
</td>
</tr>
<tr>
<td>e-mail:<br>
<input type="text" name="senders_email" size="23" maxlength="50" class="input">
</td>
</tr>
<tr>
<td>Details(*):<br>
<textarea name="message" cols="19" wrap="VIRTUAL" rows="6" class="textarea"></textarea>
</td>
</tr>
<tr valign="top">
<td>
<input type="submit" name="action" value="Submit" class="button">
<input type="reset" value="Reset" class="button">
<input type="hidden" name="action" value="add">
<input type="hidden" name="id" value="25">
</td>
</tr>
</table>
</form>
</body>
</html>
With this method, you don't even need a separate file for the popup message.
Julie Meloni's PHP Essentials was a very easy way to step into PHP, I picked it up back in early 2000 but its still great to learn the essentials. The PHP books I've gotten since deal mainly with PHP/MySQL integration, maybe someone else has a good suggestion?
merdolator
10-18-2002, 12:05 AM
nice!
thats some hefty scripting.
it seems i need to concentrate more on the javascript side of this for myself.
pez... i do like your method and idea... earlier today (yesterday haha) i implemented some improvements and incorporated a similar idea:
1) i added a dropdown menu in the form for selection of the value $subject to be put into the email headers. no longer hard coded.
2) i made the form itself a popup window launched by a javascript text link which works well with number...
3) once the form is submitted, the .php file echos confirmation and autocloses the popup form/confirmation window after about 4-5 seconds.
neat stuff. :p
<script language="javascript">setTimeout("self.close();",4000)</script>
<body bgcolor=cccccc topmargin=0 leftmargin=0>
<font color=000000 face=verdana>
<br>
<?php_track_vers?>
<?php
$msg .= "name:\t$senders_name\n";
$msg .= "email:\t$senders_email\n";
$msg .= "subject:\t$subject\n";
$msg .= "message:\t$message\n\n";
$mailheaders .= "from: $senders_name <$senders_email>\n";
$mailheaders .= "subject: $subject\n\n";
mail("emailofchoice@domain.com", $subject, $msg, $mailheaders);
echo "<h1 align=center>Thanks, $senders_name!</h1>";
echo "<p align=center>Your submission has been accepted.</p>";
?>
<center>
This window will close itself.
</font>
</center>
</body>
i've tested it a bunch... it seems to work. yay! :cool:
once again thank you for your creative solutions.
pezland
10-18-2002, 12:30 AM
Guess I went a little overboard there, my bad... but I'm glad you could glean something useful out of it, hehe. One small note:
<?php_track_vers?>
should actually be
<?php_track_vars?>
;) as in variables
merdolator
10-18-2002, 10:10 AM
<?php_track_vers?>
should actually be
<?php_track_vars?>
as in variables
:eek:
see ... now thats exactly why i am here.
i was wondering why things would pass through without being completed and the form would still be accepted. guess i need to understand the language better so when i proofread my scripting it will make enough sense to me. funny thing is that typo causes no error. i have a few minor tweaks on this site to do and then i will post the link once it goes live so anyone who is interested can see the results in action.
also... nice job on your website. i checked it out up an down last night. very clean look. comprehensive layout. nice art direction. unfortunately the only games i know about are on the sega genesis downstairs. if you need a review for NHL 92 or something... himmie up with an email haha.
is writing for a gaming industry online mag your main job?
...always wondered if there was enough money out there to start a special interest/genre e-zine.
once again, thank you kindly for your advice and direction. wish i had more knowledge in this area to support others as much.
pezland
10-18-2002, 10:35 PM
Thank you about the website =). SG is...hm, well its certainly a job to maintain (I am the group's only designer/developer/anything web or graphical person) which also means I don't actually write for the group, but it doesn't really pay what we'd like it to.
The early days were great, when we'd just founded the company, before the tech bust came around, we were constantly being approached by game companies and publishers to write for them, so, at that time it was actually a decent profit. So now I also freelance and my husband (also in the group) has his job. Anyway, we hope for things to change soon.
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.