logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-24-2012, 02:25 PM   #1
Crumpy1
Crumpy1's Avatar
 
Join Date: Aug 2011
Location: England
Posts: 246
Question Mail Form

I am looking to edit my php code to make my own webpages display my thank you message when people submit a form from my website.

I have attached the code of my current form, however these only produce basic text screens and i would like them to be redirected to a pre-made webpage so it doesnt look so tackey. I am new to php so i have used a template to do this.

I have another form on my website which will require a copy of the submited form back to the sender via email, but again do not know where in this code it goes.

Any Help would be much appreciated.

Thanks
Attached Files
File Type: txt mailprocess.txt (3.3 KB, 5 views)
Crumpy1 is offline   Reply With Quote
Old 01-25-2012, 12:13 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

where you have
Code:
if ( mail($to, $subjectline, $body, $security, "-f".$email)) {
echo $thanks;
} else {
echo "The email failed to send! Please try again later"; // Message If mail not sent
   }
change to edit to the page you want
Code:
if ( mail($to, $subjectline, $body, $security, "-f".$email)) {
header('Location: http://www.example.com/thanks.html');
} else {
echo "The email failed to send! Please try again later"; // Message If mail not sent
   }
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 01-25-2012, 08:22 AM   #3
Crumpy1
Crumpy1's Avatar
 
Join Date: Aug 2011
Location: England
Posts: 246
Default

Thank you for that, it works perfectly. If i wanted to email a copy of the reply to the sender where would i put that in the code? i am assuming it would go here $to='admin@localhost'; but do not know how to do an & in PHP. The text field id for where they type their email is 'email' incase you need to know.
Crumpy1 is offline   Reply With Quote
Old 01-25-2012, 11:34 AM   #4
Crumpy1
Crumpy1's Avatar
 
Join Date: Aug 2011
Location: England
Posts: 246
Default

Sorry to be a pain, but now i have added validation to my form this code has caused me even more errors. it runs the code below which forces users to complete the non mandatory fields before submitting. How can i delete this section? i have tried deleting the code after 'else' but that produces a white page on submit. This is also the form where the response will need to go to myself and the sender.

if any1 can help i would be extremeley appreciative.

Thanks

Code:
// The ['email'] should match the name= in the email text input box in your form. Used for email validation.
 
// DO NOT CHANGE THIS HERE. Change your form to match this.
 
$email = $_POST['email'] ; // collect users email from form for the email header.
 
// Collect all information from form and check all fields have been filled in.
 
if (sizeof($_POST)) {
 
$body = "";
 
while(list($key, $val) = each($_POST)) {
 
if ($key == "Submit") {
 
//do nothing
 
}
 
else {
 
$body .= "$key:\n $val\r\n";
 
// Checks if $val contains data
 
if(empty($val)) {
 
echo ("<b><p><li>One or more required fields have not been filled in.</li></p>
 
<p><li>Please go <a href='javascript: history.go(-1)'>Back</a> and try again</li></p></b>");
 
exit();
 
}
 
}
 
}}

Last edited by Corrosive; 01-25-2012 at 11:45 AM.. Reason: wrapped code
Crumpy1 is offline   Reply With Quote
Old 01-26-2012, 01:48 AM   #5
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

post the code what you have now its not clear to me at the moment
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 01-26-2012, 08:09 AM   #6
Crumpy1
Crumpy1's Avatar
 
Join Date: Aug 2011
Location: England
Posts: 246
Default

Quote:
Originally Posted by edbr View Post
post the code what you have now its not clear to me at the moment
The code as it is atm is below. Thanks!

Code:
<?

error_reporting(E_ALL);

/******************************************************

********    Secure mailing script     *****************

********    Copyright David Wilde     *****************

*******************************************************

You can add your template to this page.

Make your form action value the absolute or relative path to the location of this script once it is uploaded to your site.

Example;

Absolute path: <form method="post" action="http://www.yourdomain.com/scripts/mailprocess.php">

OR relative path: <form method="post" action="scripts/mailprocess.php">

Assuming you have a scripts folder and you upload the script to that folder.

The script Checks that all fields contain information and validates the email address.

You must have the email text field in your form set with the name of  'email' the name is case sensative, so make sure it is  in lowercase.

*/

###################################################################################

// Start config variables

// ONLY CHANGE THE DETAILS IN BETWEEN THE QUOTES; E.G 'your@email-address.com'

//

$to='admin@localhost'; // You must change this! This should be the email address you want the form information sent to.

//

$subjectline='Web site form - Contact Us'; // The email subject line. You may leave this as is.

//

####################################################################################

##                           Do Not Edit Below this Line                          ##

####################################################################################

//

$thanks="<h1> We have received your message.</h1><br /> 

<p>We will deal with it as soon as possible</p> <p><ul><li>Go <a href='/'>Back</a> back to the Home Page/li></ul>"; // This is the message given after successfull submission of form.

// The ['email'] should match the name= in the email text input box in your form. Used for email validation.

// DO NOT CHANGE THIS HERE. Change your form to match this.

$email = $_POST['email'] ; // collect users email from form for the email header.

// Collect all information from form and check all fields have been filled in.

if (sizeof($_POST)) {

$body = "";

while(list($key, $val) = each($_POST)) {

if ($key == "Submit") {

//do nothing

}

else {

$body .= "$key:\n $val\r\n";

// Checks if $val contains data

if(empty($val)) {

echo ("<b><p><li>One or more required fields have not been filled in.</li></p>

<p><li>Please go <a href='javascript: history.go(-1)'>Back</a> and try again</li></p></b>");

exit();

}

}

}}

// Validate email address

if(!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$/",$email)){

echo ("<b><li>Invalid email address entered. Go <a href='javascript: history.go(-1)'>Back</a> and try again</li></b>");

exit();

}

// Clean up email address

if (get_magic_quotes_gpc()){

        $email = stripslashes($email);

}

// Set headers

$security = "From: ".$email."\r\n";

$security .= "Reply-To: ".$email."\r\n";

$security .= "Return-Path: \r\n";

$security .= "CC: \r\n";

$security .= "BCC: \r\n";

ini_set("sendmail_from", $email); 

// Send the email.

if ( mail($to, $subjectline, $body, $security, "-f".$email)) {

header('Location:http://localhost\HFCC\Email_Responses\email_App_Response.html');

} else {

header('Location:http://localhost/HFCC/Email_Responses/failed.html'); // Message If mail not sent

   }

?>

Last edited by Corrosive; 01-26-2012 at 08:24 AM.. Reason: wrapped code
Crumpy1 is offline   Reply With Quote
Old 01-26-2012, 08:25 AM   #7
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

Hi Crumpy1. We don't mind you posting code but please wrap it in code tags (the # symbol at the top of the text editor) to keep it nice and neat. Thank you - your friendly admin
Corrosive is offline   Reply With Quote
Old 01-26-2012, 08:31 AM   #8
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

i havent tested this as im running late , but try this I simplyfied it , ionly left email validation in it. If it fails ill look tomorrow or maybe corrosive will help look for unbalanced braces etc

Code:
<?php

error_reporting(E_ALL);

/************************************************** ****

******** Secure mailing script *****************

******** Copyright David Wilde *****************

************************************************** *****

You can add your template to this page.

Make your form action value the absolute or relative path to the location of this script once it is uploaded to your site.

Example;

Absolute path: <form method="post" action="http://www.yourdomain.com/scripts/mailprocess.php">

OR relative path: <form method="post" action="scripts/mailprocess.php">

Assuming you have a scripts folder and you upload the script to that folder.

The script Checks that all fields contain information and validates the email address.

You must have the email text field in your form set with the name of 'email' the name is case sensative, so make sure it is in lowercase.

*/

################################################## #################################

// Start config variables

// ONLY CHANGE THE DETAILS IN BETWEEN THE QUOTES; E.G 'your@email-address.com'

//

$to='admin@localhost'; // You must change this! This should be the email address you want the form information sent to.

//

$subjectline='Web site form - Contact Us'; // The email subject line. You may leave this as is.

//

################################################## ##################################

## Do Not Edit Below this Line ##

################################################## ##################################

//

$thanks="<h1> We have received your message.</h1><br />

<p>We will deal with it as soon as possible</p> <p><ul><li>Go <a href='/'>Back</a> back to the Home Page/li></ul>"; // This is the message given after successfull submission of form.

// The ['email'] should match the name= in the email text input box in your form. Used for email validation.

// DO NOT CHANGE THIS HERE. Change your form to match this.

$email = $_POST['email'] ; // collect users email from form for the email header.

// Collect all information from form and check all fields have been filled in.


// Validate email address

if(!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$/",$email)){

echo ("<b><li>Invalid email address entered. Go <a href='javascript: history.go(-1)'>Back</a> and try again</li></b>");

exit();

}

// Clean up email address

if (get_magic_quotes_gpc()){

$email = stripslashes($email);

}

// Set headers

$security = "From: ".$email."\r\n";

$security .= "Reply-To: ".$email."\r\n";

$security .= "Return-Path: \r\n";

$security .= "CC: \r\n";

$security .= "BCC: \r\n";

ini_set("sendmail_from", $email);

// Send the email.

if ( mail($to, $subjectline, $body, $security, "-f".$email)) {

header('Location:http://localhost\HFCC\Email_Responses\email_App_Response. html');

} else {

header('Location:http://localhost/HFCC/Email_Responses/failed.html'); // Message If mail not sent

}

?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 01-26-2012, 08:51 AM   #9
Crumpy1
Crumpy1's Avatar
 
Join Date: Aug 2011
Location: England
Posts: 246
Default

Quote:
Originally Posted by Corrosive View Post
Hi Crumpy1. We don't mind you posting code but please wrap it in code tags (the # symbol at the top of the text editor) to keep it nice and neat. Thank you - your friendly admin
I will do in future. Sorry about that i did not realise that was how it was done.
Crumpy1 is offline   Reply With Quote
Old 01-26-2012, 08:53 AM   #10
Crumpy1
Crumpy1's Avatar
 
Join Date: Aug 2011
Location: England
Posts: 246
Default

Quote:
Originally Posted by edbr View Post
i havent tested this as im running late , but try this I simplyfied it , ionly left email validation in it. If it fails ill look tomorrow or maybe corrosive will help look for unbalanced braces etc

Code:
<?php
 
error_reporting(E_ALL);
 
/************************************************** ****
 
******** Secure mailing script *****************
 
******** Copyright David Wilde *****************
 
************************************************** *****
 
You can add your template to this page.
 
Make your form action value the absolute or relative path to the location of this script once it is uploaded to your site.
 
Example;
 
Absolute path: <form method="post" action="http://www.yourdomain.com/scripts/mailprocess.php">
 
OR relative path: <form method="post" action="scripts/mailprocess.php">
 
Assuming you have a scripts folder and you upload the script to that folder.
 
The script Checks that all fields contain information and validates the email address.
 
You must have the email text field in your form set with the name of 'email' the name is case sensative, so make sure it is in lowercase.
 
*/
 
################################################## #################################
 
// Start config variables
 
// ONLY CHANGE THE DETAILS IN BETWEEN THE QUOTES; E.G 'your@email-address.com'
 
//
 
$to='admin@localhost'; // You must change this! This should be the email address you want the form information sent to.
 
//
 
$subjectline='Web site form - Contact Us'; // The email subject line. You may leave this as is.
 
//
 
################################################## ##################################
 
## Do Not Edit Below this Line ##
 
################################################## ##################################
 
//
 
$thanks="<h1> We have received your message.</h1><br />
 
<p>We will deal with it as soon as possible</p> <p><ul><li>Go <a href='/'>Back</a> back to the Home Page/li></ul>"; // This is the message given after successfull submission of form.
 
// The ['email'] should match the name= in the email text input box in your form. Used for email validation.
 
// DO NOT CHANGE THIS HERE. Change your form to match this.
 
$email = $_POST['email'] ; // collect users email from form for the email header.
 
// Collect all information from form and check all fields have been filled in.
 
 
// Validate email address
 
if(!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$/",$email)){
 
echo ("<b><li>Invalid email address entered. Go <a href='javascript: history.go(-1)'>Back</a> and try again</li></b>");
 
exit();
 
}
 
// Clean up email address
 
if (get_magic_quotes_gpc()){
 
$email = stripslashes($email);
 
}
 
// Set headers
 
$security = "From: ".$email."\r\n";
 
$security .= "Reply-To: ".$email."\r\n";
 
$security .= "Return-Path: \r\n";
 
$security .= "CC: \r\n";
 
$security .= "BCC: \r\n";
 
ini_set("sendmail_from", $email);
 
// Send the email.
 
if ( mail($to, $subjectline, $body, $security, "-f".$email)) {
 
header('Location:http://localhost\HFCC\Email_Responses\email_App_Response. html');
 
} else {
 
header('Location:http://localhost/HFCC/Email_Responses/failed.html'); // Message If mail not sent
 
}
 
?>
Thank you for the revised code, i will try this later and repost tommorow! Thank you so much for your help it is genuinly appreciated.
Crumpy1 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:49 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com