Jump to content

mailform


crumpy1

Recommended Posts

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 premade webpage so it doesnt look so tackey. I am new to php but am desperatly trying to grasp the basics.

 

I am trying to also send 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

17412_.php

Link to comment
https://forums.phpfreaks.com/topic/255608-mailform/
Share on other sites

if you want to redirect the user to another webpage after a successful email send then change the end of your script to this:

<?php
// Send the email.
if ( mail($to, $subjectline, $body, $security, "-f".$email)) {
header('Location:confirmationpage.php'); // this will redirect the page to confirmation.php
// if you want to send a confirmation email to the customer then you could throw it in here

} else {
header('Location:failure.php');
   }

Link to comment
https://forums.phpfreaks.com/topic/255608-mailform/#findComment-1310673
Share on other sites

if you want to redirect the user to another webpage after a successful email send then change the end of your script to this:

<?php
// Send the email.
if ( mail($to, $subjectline, $body, $security, "-f".$email)) {
header('Location:confirmationpage.php'); // this will redirect the page to confirmation.php
// if you want to send a confirmation email to the customer then you could throw it in here

} else {
header('Location:failure.php');
   }

 

Thank you so much for the help it is now loading my webpage. Your instructions were so clear so thank you!! Sorry to be a pain though but i have 1 more issue.

 

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. In this form also i would like the response to go to myself and the sender.

 

if any1 can help i would be extremeley appreciative.

 

Thanks

 

 

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

 

 

}

 

 

}

 

 

}}

 

Link to comment
https://forums.phpfreaks.com/topic/255608-mailform/#findComment-1311028
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.