Click to See Complete Forum and Search --> : Need help with an email sent confirmation.


soulflycrx
12-09-2003, 02:05 PM
Ok. I am new to php. I have set up an email form for a website that I am building for my mom as a favor to her. I have got the email form to send me an email, and all is fine in that department. What I need now is some sort of screen to give the user confirmation that the email was sent, and then perhaps bring the user back to the contact page.

here is the page that I am working on: http://www.wildernesscrossing.com/contact.php

Here is the code...

Does anybody have a good solution for me? THANKS! :p


<?php

// if submitted form process and send mail
if ($REQUEST_METHOD == "POST") {

// just to be on the safe side
// I'll strip out HTML tags
// (scripting code may mess with some email clients)
$realname = strip_tags($realname);
$email = strip_tags($email);
$feedback = strip_tags($feedback);

$sendto = "ryans@accesscomm.ca";
$subject = "Question or comment from Wilderness Crossing.";
$message = "$realname, $email\n\n$feedback";

mail($sendto, $subject, $message);

}

?>


<html>
<head>
<title>Wilderness Crossing - Wildlife &amp; Gift Gallery: Contact Us</title>

<script language="JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
</head>

<body background="images/bg2.gif" GPROPERTIES="FIXED" bgcolor="#CCCC99" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#006699" vlink="#006699" alink="#006699">
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/header.gif" width="640" height="102"></td>
</tr>
<tr>
<td height="133" valign="top">
<table width="205" border="0" cellspacing="0" cellpadding="0" height="158">
<tr>
<td width="19" height="17">&nbsp;</td>
<td width="188" height="17">&nbsp;</td>
</tr>
<tr>
<td width="19" height="5">&nbsp;</td>
<td width="188" height="5" valign="top">
<div align="left"> <font face="Georgia, Times New Roman, Times, serif" size="3"><b><i>Contact
Us:</i></b></font></div>
</td>
</tr>
<tr>
<td width="19" height="11">&nbsp;</td>
<td width="188" height="11"><font face="Arial, Helvetica, sans-serif" size="3"></font></td>
</tr>
<tr>
<td width="19" height="2">&nbsp;</td>
<td width="188" height="2"><font face="Arial, Helvetica, sans-serif" size="3"></font></td>
</tr>
<tr>
<td width="19" height="11">&nbsp;</td>
<td width="188" height="11">&nbsp;</td>
</tr>
<tr>
<td width="19" height="2">&nbsp;</td>
<td width="188" height="2"><font face="Arial, Helvetica, sans-serif" size="3"></font></td>
</tr>
<tr>
<td width="19" height="2">&nbsp;</td>
<td width="188" height="2">&nbsp;</td>
</tr>
<tr>
<td width="19" height="11">&nbsp;</td>
<td width="188" height="11">&nbsp;</td>
</tr>
<tr>
<td width="19" height="2">&nbsp;</td>
<td width="188" height="2"><font face="Georgia, Times New Roman, Times, serif" size="3"><b><a href="index.html"><font color="#FFFFFF">Back
to Home</font></a></b></font></td>
</tr>
</table>
<div id="Layer1" style="position:absolute; width:517px; height:120; z-index:1; left: 219px; top: 108px">
<div align="center">
<table width="517" border="1" height="59" cellpadding="7" cellspacing="0" bgcolor="#999966">
<tr>
<td height="121" valign="top">
<div align="center"><b><font face="Georgia, Times New Roman, Times, serif" color="#993300" size="4">~
Contact Us ~</font></b></div>
<p><font face="Georgia, Times New Roman, Times, serif" size="3"><b>E-mail:</b><br>
For questions, and all other inquiries, please use the e-mail
form below. We will be sure to reply asap.</font></p>

<!-- *** START HTML FORM -->
<form action="<? echo("$script_name"); ?>" METHOD="POST">
<table cellpadding=4 cellspacing=0 border=0>
<tr><td><b>Name: </b></td><td><input type="text" name="realname" size=25></td></tr>
<tr><td><b>Email:</b></td><td><input type="text" name="email" size=25></td></tr>
<tr>
<td colspan=2><b>Questions / comments:</b><br>
<textarea name="feedback" rows=4 cols=40 wrap=physical></textarea>
</td></tr>
<tr>
<td colspan=2 align=left height="16">
<input type="submit" value="Send Feedback"></td></tr>
</table>
</form>
<!-- *** END HTML FORM -->

<p><font size="3"><b><font face="Georgia, Times New Roman, Times, serif">Fax:</font></b><font face="Georgia, Times New Roman, Times, serif">
(306) 781-2513</font></font>
<p><font size="3" face="Georgia, Times New Roman, Times, serif"><b>Phone:
</b>1-877-781-2498 (toll free)</font></p>
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</body>
</html>

Zibings
12-09-2003, 03:47 PM
I do little scripts like this a lot, and I've found there are a few ways you can code things to make it easier on yourself. Sometimes working with PHP and HTML at the same time can be confusing.

One of the biggest things I ever caught off of someone else, was splitting up HTML into re-usable sections. For instance, you know that all pages have three BASIC sections to them:

header
body
footer

With that in mind, why not literally make a header and footer file that can be included to output the HTML for you whenever you want. That way, all you have to fill in is the middle part of the site (the body), and you can do whatever you want with that without having a PHP file that is 2,000 lines long and a pain to debug.

Let's say that you do this, you can setup your code fairly simple now.


<?php

// if submitted form process and send mail
if ($REQUEST_METHOD == "POST") {

// just to be on the safe side
// I'll strip out HTML tags
// (scripting code may mess with some email clients)
$realname = strip_tags($realname);
$email = strip_tags($email);
$feedback = strip_tags($feedback);

$sendto = "ryans@accesscomm.ca";
$subject = "Question or comment from Wilderness Crossing.";
$message = "$realname, $email\n\n$feedback";

if ( mail($sendto, $subject, $message) ) {
require ( "header.php" ); //header file with top part of page

echo ( "Your email has been sent. We thank you, and will contact you within 24 hours." );

require ( "footer.php" ); //footer file with bottom of page
}

else {
require ( "header.php" ); //header file with top part of page

echo ( "We were not able to send your email. Please try again in a few minutes." );
//echo your form here, maybe give them all of the information they filled in again

require ( "footer.php" ); //footer file with bottom of page
}
}

else {
require ( "header.php" );

//your form code

require ( "footer.php" );
}

?>


It makes it a lot easier to deal with, and easier to read! Hope this helps!

olaf
12-10-2003, 01:18 AM
A simple way, put this after your mail function:

echo "<script>alert('Mail status OK!')</script>";