Jump to content

Form trouble


Sean_J

Recommended Posts

Hello Guys,

 

I created a basic email form using an online form generater. Instead on seeing a message saying "Success! Your email was sent!" . Would it be possible to redirect them to another page on my website? If so could someone please show me how as I am a complete novice?

 

The generator has come up with the following coding.

 

<?php

$EmailFrom = $_POST['EmailFrom'];

$name_ = Trim($_POST['name_']);

$age = Trim($_POST['age']);

$location = Trim($_POST['location']);

 

$EmailTo = "[email protected]";

$Subject = ""; /// Add a subject

 

$validationOK=true;

if (Trim($EmailFrom)=="") $validationOK=false;

if (!$validationOK) {

  echo "Error! Email was not sent. Please check you code.";

  exit;

}

 

 

$Body = "";

$Body .= "Name :\n$name_\n\n";

$Body .= "Age:\n$age\n\n";

$Body .= "Location:\n$location\n\n";

 

if($Subject == NULL) {$Subject = "From $EmailFrom";}

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

 

if ($success){ echo "Success! Your email was sent!";}

else{  echo "Error! Your email was not sent!";}

 

?>

 

Thank you in advance

 

Sean

Link to comment
https://forums.phpfreaks.com/topic/92318-form-trouble/
Share on other sites

Thank you for your replies.

 

Fesan,

 

Should the script look like this if I wanted to redirect them to my homepage

 

<?php

$EmailFrom = $_POST['EmailFrom'];

$name_ = Trim($_POST['name_']);

$age = Trim($_POST['age']);

$location = Trim($_POST['location']);

 

$EmailTo = "[email protected]";

$Subject = ""; /// Add a subject

 

$validationOK=true;

if (Trim($EmailFrom)=="") $validationOK=false;

if (!$validationOK) {

  echo "Error! Email was not sent. Please check you code.";

  exit;

}

 

 

$Body = "";

$Body .= "Name :\n$name_\n\n";

$Body .= "Age:\n$age\n\n";

$Body .= "Location:\n$location\n\n";

 

if($Subject == NULL) {$Subject = "From $EmailFrom";}

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

 

if ($success){

header('location:*http://www.mysite.com/*');

}

else{  echo "Error! Your email was not sent!";}

 

?>

 

Thanks again

 

Sean

Link to comment
https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473027
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.