Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
->> i hv created a form page in php.

->> After click on the submit button it redirect to another php page(sendmail.php)

->> every time the user refresh the page after submit it send a mail every time.

Please help how we restrict to send mail after once the form submit.

The sendmail.php page is as below


XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>

<body>
<?php
 if(!empty($_REQUEST["email"]))
{

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "kadian2010@gmail.com";
    $email_subject = "Admission query details";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_REQUEST['name']) ||
        !isset($_REQUEST['email']) ||
        !isset($_REQUEST['phone']) ||
        !isset($_REQUEST['course']) ||
        !isset($_REQUEST['city']) ||
        !isset($_REQUEST['comments']) ||
        !isset($_REQUEST['security_code'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $first_name = $_REQUEST['name']; // required
    $email_from = $_REQUEST['email']; // required
    $telephone = $_REQUEST['phone']; // required
    $course = $_REQUEST['course']; // required
    $city = $_REQUEST['city']; // required
    $comments = $_REQUEST['comments']; // not required
    $security = $_REQUEST['security_code']; // not required


    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Course: ".clean_string($course)."\n";
    $email_message .= "City: ".clean_string($city)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
    $email_message .= "Security_Code: ".clean_string($security)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
echo"Thank you for contacting us. We will be in touch with you very soon.";
}
else{
echo"Please first fill the Enquiry Form correctively";
}
?>
<br /><br>
<a href="http://admissioncart.dx.am/contact-us.php">Click here</a> to Contact Us

</body>
</html>
Posted
Updated 7-Jun-13 3:00am
v2
Comments
Prasad Khandekar 7-Jun-13 9:26am    
Hello Ashok,

Do you mean to say after clicking on submit button of page 1 it gets posted to sendmail.php? It can not be redirect.
ashok.kadian 8-Jun-13 0:32am    
after click on submit button it redirect to sendmail.php, it is okk. But after open sendmail.php page a mail has send to my email id.
Every time the user refresh the sendmail.php page it send same mail to my emailid every time with same user detail.I want to send email only one at first sendmail.php load.

1 solution

Use a flag variable. Initialize it to false. When the email is sent, change its value to true.
Then, test the value of this flag at the same time of
PHP
!empty($_REQUEST["email"])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900