telekineser
telekineser

Reputation: 88

Form submission opens php page

I have a form on html page. it has action as mailer.php. All code works properly, but on submission, page goes to mailer.php and browser shows an empty page on screen

contactus.html form tag:

<form id="form_20" action="mailer.php" method="post" target="_self" 
      enctype="multipart/form-data">
    //input fields here
</form>

mailer.php file:

<?php
$to = '---------------'; //Removed for privacy
$subject = 'New Enquiry';

$name = $_POST['Name'];
$tel = $_POST['Number'];
$email = $_POST['Email'];
$comments = $_POST['Message'];

$body = "From: $name \nNumber: $tel \nEmail id: $email \nComments: $comments";
$headers = 'FROM: ---------------------------'.PHP_EOL; //Removed for privacy
mail($to, $subject, $body, $headers);
echo '<script>alert("Your data has been submitted.");</script>';
?>

The code works fine, I get the mail too. The only problem I have is that the page redirects to mailer.php

P.S. : If anyone finds this a duplicate question, please comment the link to the question it duplicates so I get my answer. Thanks

Upvotes: 0

Views: 46

Answers (1)

user557846
user557846

Reputation:

to send the user back to the previous page:

header('Location: http://www.example.com/foo.php?back=yes'); //add your url

after the mail call, and remove the script

on foo.php

if ($_GET['back']=='yes'){
echo '<script>alert("Your data has been submitted.");</script>';
}

Upvotes: 3

Related Questions