Forum Moderators: coopster
-------------------------------------------
<p>In the meantime, please send me an email </p>
<form method="post" action="../send.php">
Name:<br /><input name="name" type="text" size="30" /><br /><br />
Email:<br /><input name="email" type="text" size="30" /><br /><br />
Comments:<br /><input name="subject" type="text" size="30" /><br /><br />
Message:<br /><textarea name="msg" cols="24" rows="3"></textarea>
<br /><br />
<input type="reset" value="Reset" />
<input type="submit" value="Send" />
</form>
-------------------------------------------
Make a new page, called thankyou.php, or submit.php, or send.php or likewise. Have the following code in the body of your document.
-------------------------------------------
<?php
$to = "mail@mail.com"; // change to your email address
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['msg'];
$d = date('l dS \of F Y h:i:s A');
$sub = "form to mail";
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes = "Subject: ".$subject."\n";
$mes .= "Message: ".$msg."\n";
$mes .= "Name: ".$name."\n";
$mes .= 'Email: '.$email."\n";
$mes .= 'Date & Time: '.$d;
if (empty($name) ¦¦ empty($email) ¦¦ empty($subject) ¦¦ empty($msg))
{
echo " <h3>Sorry all fields are required.</h3>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <h3>Sorry the email address you entered looks like it's invalid.</h3>";
}
else
{
mail($to, $sub, $mes, $headers);
print " <h3>Thank you ".$name." for contacting us.<br>We will get back to you as soon as posiable<br></h3>";
}
?>
The long php code i presented is the php "results" or "redirected" page, you find that in the <form> tag. In the below case, the address is action="redirectedlink.php" sends the form to the php page, and emails you the result. You will get an email with all the forms filled in.
If you just want a comment box, try this:
____________
IN TEMPLATE:
____________
<form method="post" action="redirectedlink.php">
Comments:<br />
<input name="subject" type="text" size="30" /><br />
<input type="submit" value="Send" />
</form>
After your mailing code, just add:
header("Location: [webmasterworld.com");...]
exit();
Then, after the script is done sending you the email, it redirects the visitor elsewhere.
I don't want to add anything to the template already. I'd just like to have the information emailed to me after they click the 'Submit' button and then have them automatically redirected to another website of my choice.
I've re-read this thread, and so yes, you will want to create a new script, and you will need to change the submit link on the form to point to your new script. In that script you will want to validate the input, and if OK send yourself mail and redirect. If something fails in the validation you will want to redirect back to your form page. NOTE - You CANNOT output anything from this script or the redirect will not work.
[edited by: grandpa at 6:36 am (utc) on Dec. 31, 2006]
Here's the actual code (or a portion of it) from the section of the form. If you need more info let me know, or you can stick me as well:
<table width="235" style="height:217px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" height="51"><img src="images/spacer.gif" alt="" width="4" height="1">Your full name:<br><input name="" type="text"></td>
</tr>
<tr>
<td valign="top" height="51"><img src="images/spacer.gif" alt="" width="4" height="1">E-mail address:<br><input name="" type="text"></td>
</tr>
<tr>
<td valign="top" height="115"><img src="images/spacer.gif" alt="" width="4" height="1">Your telephone:<br><input name="" type="text"></td>
</tr>
</table>
</td>
<td valign="top" width="270">Message:<br>
<textarea name="" rows="0" cols="0"></textarea><br><br style="line-height:5px; ">
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit"> <a href="http://www.widgets.com">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="100%" style="background:url(images/bgr_3.jpg) left top repeat-x #838383 ">
<table width="696" style="height:100%; " border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" width="190" class="footer">
<div style="margin:39px 0 0 39px; ">
<span>
</span>
</div>
</td>
Change the URL on this line to point to your validation script. I made minor modifications to BlueGhost's example, calling it mailtest.php. Thus, the submit URL for your form would become something like: http://www.yourdomain.com/mailtest.php
I am assuming that widgets.com is the site where you want to redirect?
<?php
// This is mailtest.php
$to = "mail@mail.com"; // change to your email address
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['msg'];
$d = date('l dS \of F Y h:i:s A');
$sub = "form to mail";
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes = "Subject: ".$subject."\n";
$mes .= "Message: ".$msg."\n";
$mes .= "Name: ".$name."\n";
$mes .= 'Email: '.$email."\n";
$mes .= 'Date & Time: '.$d;
if (empty($name) ¦¦ empty($email) ¦¦ empty($subject) ¦¦ empty($msg))
{
// Empty form field
// Redirect back to the form
header("Location: http://www.yourdomain.com/form.php");
exit();
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
// Invalid email address
// Redirect back to the form
header("Location: http://www.yourdomain.com/form.php");
exit();
}
else
{
// Success - Mail to yourself and redirect
mail($to, $sub, $mes, $headers);
header("Location: http://www.widgets.com/");
exit();
}
?>
I tried to do the changes as you suggested and now after I fill out the forms and comments I don't get any email. It now just redirects. Can you see anything here that might be wrong?
Here is the mail.php I'm using:
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$to = 'support@widgets.com'; //Address mail is to be sent to
$from = 'support@widgets.com'; //Sets the senders mail address
$subject = $_REQUEST['subject']; //Sets the subject from the mail form
$confirm = '/'; //change this value to your preferred page(it's set for homepage now)
$error = 'mailerror.php'; //Sets the page to direct to if the mail is unsent
// Don't touch anything else //
$mailheader = "";
$mailheader .= "From: support@widgets.com\r\n"; //so they know who it came from
if (isset($HTTP_POST_VARS)){
$mailbody = '';
while (list($key, $value) = each($HTTP_POST_VARS))
{
$mailbody .= $key . ' = ' . $value . "\r\n";
}
}
$mailforms = mail($to, $subject, $mailbody, $mailheader);
if($mailforms)
{
header('Location: ' . $confirm);
}
else
{
include('Location: ' . $error);
}
?>
</body>
</html>
if the mail function wasn't returning true then it should go to this line
include('Location: ' . $error);
which isn't right, you should either change include to header or you need to just have
include $error;
as long as the $error page is in the same firectory as your mail script
$mailheader = "";
$mailheader .= "From: support@widgets.com\r\n"; //so they know who it came from
$mailheader = "From: support@widgets.com"; //so they know who it came from
Try printing your variables to make sure they are what you expect. Just for testing, add these next 2 lines just before you execute the mail function.
echo "<br />To= $to Subj= $subject From = $mailheader";
exit();
$mailforms = mail($to, $subject, $mailbody, $mailheader);
(You're almost there!)
you will want something like
<form name="contactform" action="/mail.php" method="post">
that will point your form to the mail script. Then you can print your posted variables in your mail script by putting something like this in it
echo '<pre>my posted variables<p>';
print_r($_POST);
echo '</pre>';
then keep all your processing after that and do as grandpa showed to make sure you are getting those posted values properly into the other vars.
then it is a matter of getting the mail to go and then redirecting.
echo "<br />To= $to Subj= $subject From = $mailheader";
exit();
$mailforms = mail($to, $subject, $mailbody, $mailheader);
All this will do is display the information that you are trying to use to send your mail. You can visually see if there is something wrong with an address that will keep your mail form working. The exit(); will stop your code from redirecting so you can see the results. If they look OK, but the mail still won't work, post those results here so we can have a second look.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK HREF="style.css" TYPE="text/css" REL="stylesheet">
<title>Home</title>
</head>
<body>
<table width="100%" style="height:100%; " border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" height="190">
<table width="100%" style="height:190px; " border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" height="97" style="background:url(images/bgr_1.jpg) left repeat-x; ">
<table width="696" style="height:97px; " border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" width="191"><img src="images/logo.gif" alt="DTS" width="69" height="85"></td>
<td valign="top" width="351"><img src="images/slogan.jpg" alt="" style="margin-top:40px; "></td>
<td valign="top" width="154">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="93">
<table width="100%" style="height:93px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="191"><img src="images/spacer.gif" alt=""></td>
<td valign="top" width="505"><img src="images/about.jpg" alt="" border="0" style="margin-top:38px; "><img src="images/line_vertical.jpg" alt="" style="margin-left:20px; "><img src="images/services.jpg" alt="" border="0" style="margin-left:21px; "><img src="images/line_vertical.jpg" alt="" style="margin-left:19px; "><img src="images/solutions.jpg" alt="" border="0" style="margin-left:19px; "><img src="images/line_vertical.jpg" alt="" style="margin-left:19px; "><img src="images/contacts.jpg" alt="" border="0" style="margin-left:19px; ">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="416">
<table width="696" style="height:416px; " border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" width="182">
<table width="182" style="height:416px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" height="179">
<table width="182" style="height:179px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="bottom"><img src="images/1im1.jpg" alt=""></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="237"><p><img src="images/spacer.gif" alt=""></p>
<p> </p>
<p> </p>
<p>Phone: (877) 387-4829</p>
<p>Fax: (914) 459-1171 </p></td>
</tr>
<tr>
<td valign="top" height="237"> </td>
</tr>
</table>
</td>
<td valign="top" width="514">
<table width="514" style="height:416px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="9"><img src="images/spacer.gif" alt=""></td>
<td valign="top" width="505">
<table width="505" style="height:416px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" height="139">
<table width="505" style="height:139px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" height="1"><img src="images/5line_1.jpg" alt=""></td>
</tr>
<tr>
<td valign="top" height="138">
<table width="505" style="height:138px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="465" style="background:url(images/bgr_4.jpg) top left repeat-y; ">
<div style="margin:18px 0 0 19px; ">
<p align="right"><img src="images/5im1.jpg" alt="" align="left" style="margin-right:13px; "> Distributor Tax Services</p>
<p align="right">405 Tarrytown Road</p>
<p align="right">Suite 1573</p>
<p align="right"> White Plains, NY 10607 <br>
</p>
</div>
</td>
<td valign="top" width="40" style="background:url(images/bgr_5.jpg) top left repeat-y; "><img src="images/spacer.gif" alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="28"><img src="images/5line_2.jpg" alt=""></td>
</tr>
<tr>
<td valign="top" height="32"><img src="images/5_contacts.jpg" alt=""></td>
</tr>
<tr>
<td valign="top" height="217">
<form id="form" action="">
<table width="505" style="height:217px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="235">
<table width="235" style="height:217px; " border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" height="51"><img src="images/spacer.gif" alt="" width="4" height="1">Your full name:<br><input name="" type="text"></td>
</tr>
<tr>
<td valign="top" height="51"><img src="images/spacer.gif" alt="" width="4" height="1">E-mail address:<br><input name="" type="text"></td>
</tr>
<tr>
<td valign="top" height="115"><img src="images/spacer.gif" alt="" width="4" height="1">Your telephone:<br><input name="" type="text"></td>
</tr>
</table>
</td>
<td valign="top" width="270"><div align="right">Message:<br>
<textarea name="" rows="0" cols="0"></textarea>
<br>
<br style="line-height:5px; ">
<img src="images/spacer.gif" alt="" width="115" height="1"><img src="images/spacer.gif" alt="" width="19" height="1"> <a href="#"></a>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit">
<a href="http://www.widgets.com/mail.php">
</div></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="100%" style="background:url(images/bgr_3.jpg) left top repeat-x #838383 ">
<table width="696" style="height:100%; " border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" width="190" class="footer">
<div style="margin:39px 0 0 39px; ">
<span>
</span>
</div>
</td>
<td valign="top" width="506" class="footer">
<div style="margin-top:39px; "><strong><a href="index.html">Home</a><img src="images/spacer.gif" alt="" width="14" height="8"> <img src="images/line_vertical2.jpg" alt="" style="vertical-align:middle; "><img src="images/spacer.gif" alt="" width="14" height="8"><a href="recordkeeping.html">Recordkeeping</a><img src="images/spacer.gif" alt="" width="14" height="1"><img src="images/line_vertical2.jpg" alt="" style="vertical-align:middle; "><img src="images/spacer.gif" alt="" width="14" height="1"><a href="forms.html">Forms</a><img src="images/spacer.gif" alt="" width="14" height="8"><img src="images/line_vertical2.jpg" alt="" style="vertical-align:middle; "><img src="images/spacer.gif" alt="" width="14" height="1"><a href="recapexplained.htm">Recap Explained</a><img src="images/spacer.gif" alt="" width="14" height="8"><img src="images/line_vertical2.jpg" alt="" style="vertical-align:middle; "><img src="images/spacer.gif" alt="" width="14" height="1"><a href="contactus.html">Contact Us</a></strong><br>
<br style="line-height:5px; ">
<span>Distributor Tax Services © 2007</span></div>
</td>
</tr>
<tr>
<td valign="top" class="footer"> </td>
<td valign="top" class="footer"> </td>
</tr>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>