Author Topic: Mail Form Template PHP  (Read 281 times)

0 Members and 1 Guest are viewing this topic.

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Mail Form Template PHP
« on: January 27, 2012, 10:53:43 AM »
Where can i find free templates for php code that simply submits a forms content on submit. It does not need to validate fields that are not complete or anything as this has been coded into my html. I need it to send a copy of the form to the senders address i.e 'email' id and to myself. I have been using code that validates if ALL fields are complete and it is forcing users to complete even the non-mandatory fields on sumbit which i do not want or need.

Also i forgot to say that there are two webpages with the Location:() tags one for successfully sent and other for failed but i can add these in myself if i cannot find template with them already included.

Any help would be appreciated.

Thanks to anyone who helps.
« Last Edit: January 27, 2012, 10:55:31 AM by crumpy1 »

Offline spiderwell

  • Devotee
  • Posts: 779
  • Gender: Male
  • if i'm going to stare at a free avatar <(^-^)>
    • View Profile
Re: Mail Form Template PHP
« Reply #1 on: January 27, 2012, 11:16:47 AM »
why not remove the validation from what you have already
why is the man trying to pixelate my fractal lifestyle

Need a List? try www.cutandpastelists.com

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #2 on: January 27, 2012, 12:40:37 PM »
why not remove the validation from what you have already

Sorry i should have mensioned that i am only a student and have been using the college templates to sumbit my form. Attached is a copy of the code i have been using, but it keeps forcing me to complete all fields. I do not understand php yet only the very very basics.

If you do not mind tweaking this for me it would be appreciated, just to submit the form to myself and the sender ('email' id) and to send them to the appropiate webpage. Alternativly as i know it is a bit of a cheeck if you can let me know where to find templates to suit my needs that also will be hugely appreciated.

Thanks

Offline Pikachu2000

  • I hate everything.
  • Global Moderator
  • Freak!
  • *
  • Posts: 9,063
  • Gender: Male
  • Is it solipsistic in here, or is it just me?
    • View Profile
Re: Mail Form Template PHP
« Reply #3 on: January 27, 2012, 12:59:29 PM »
You seem to be confused as to what a help forum is. We're here to help people fix code, not fix code for people.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf * || Linux Help --> linuxforum.com

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #4 on: January 29, 2012, 04:34:32 PM »
You seem to be confused as to what a help forum is. We're here to help people fix code, not fix code for people.

I appreciate that, thats why i asked for pre made templates or free use code that i can implement on my own pages! Some people prefer to tweak whats already there that why i gave both as an option!

Offline AyKay47

  • Addict
  • Posts: 2,245
  • Gender: Male
  • God Bless
    • View Profile
Re: Mail Form Template PHP
« Reply #5 on: January 29, 2012, 09:52:09 PM »
if you post the code to this thread, we can certainly assist you.
RegEx Nerd
There will be a time when I will truncate all tables, and set it free.

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #6 on: January 30, 2012, 04:08:47 AM »
if you post the code to this thread, we can certainly assist you.

Thank you, i never expected people to do it all for me, i need to learn how to do it for myself and want to. I have re-attached it for you to see.

I want it to be a submit form only, i do not want it to validate any of the forms on submit and i want to be able to sent it to an address in my 'email' field as well as my own. then go to a page that either confirms it has been sent ok or failed to send.

Thanks

Offline AyKay47

  • Addict
  • Posts: 2,245
  • Gender: Male
  • God Bless
    • View Profile
Re: Mail Form Template PHP
« Reply #7 on: January 30, 2012, 07:11:29 AM »
Again:

if you post the code to this thread, we can certainly assist you.

Paste the code into this thread, don't attach it.
RegEx Nerd
There will be a time when I will truncate all tables, and set it free.

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #8 on: January 30, 2012, 08:04:59 AM »
Again:

if you post the code to this thread, we can certainly assist you.

Paste the code into this thread, don't attach it.

Sorry did not relise that is what you mean't.

Code: [Select]
<?
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/Employee_App_Response.html'); //Message if mail has been sent sucsessfully.
} else {
header('Location:http://localhost/HFCC/Email_Responses/failed.html'); // Message If mail not sent
   }
?>

Offline AyKay47

  • Addict
  • Posts: 2,245
  • Gender: Male
  • God Bless
    • View Profile
Re: Mail Form Template PHP
« Reply #9 on: January 30, 2012, 08:11:09 AM »
what part of this code do you need help with or do not understand?
RegEx Nerd
There will be a time when I will truncate all tables, and set it free.

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #10 on: January 31, 2012, 03:55:18 AM »
what part of this code do you need help with or do not understand?

I need help to remove the validation checks that force users to fill in all fields. And how to send a copy of it back to the original sender as well as me on sumbit.

Offline AyKay47

  • Addict
  • Posts: 2,245
  • Gender: Male
  • God Bless
    • View Profile
Re: Mail Form Template PHP
« Reply #11 on: January 31, 2012, 07:45:35 AM »
what part of this code do you need help with or do not understand?

I need help to remove the validation checks that force users to fill in all fields. And how to send a copy of it back to the original sender as well as me on sumbit.

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();
}
}


this bit here checks if all fields have been filled out, you can replace this bit with whatever validation you want. you can CC the email to you and the original sender in the $headers part of the email.
RegEx Nerd
There will be a time when I will truncate all tables, and set it free.

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #12 on: January 31, 2012, 12:06:06 PM »
Thank you for the help I have finally got the code working for 2 out of the 3 forms. The 1 form keeps producing 'object not found error 404' on submit. The form is in the same root folder as the other pages and share the same php code however when the others say sent sucsessfully this one gives the error message. Are there any obvious things with this error? The location of the php file in action is definetly correct and the method is set to POST.

Offline crumpy1Topic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Mail Form Template PHP
« Reply #13 on: January 31, 2012, 12:12:22 PM »
Thank you for the help I have finally got the code working for 2 out of the 3 forms. The 1 form keeps producing 'object not found error 404' on submit. The form is in the same root folder as the other pages and share the same php code however when the others say sent sucsessfully this one gives the error message. Are there any obvious things with this error? The location of the php file in action is definetly correct and the method is set to POST.

All 3 working correctly now, thank you to you all for your help!