Jump to content

Recommended Posts

Hey guys. This is my first post on this forum so sorry if I do something wrong.

 

I have a mail function in my site and it's working but I want a text above my form when you do something wrong. I have it when you do something right but if it's wrong it will take you to a new page with the errors. Plz help me. this is my php code:

<?php
if(isset($_POST['email'])) {


$email_to = "(my email)";
$email_subject = "Een e-mail van celcommunicatie";


function died($error) {


	echo "Het spijt ons, maar er waren fout (en) gevonden met het formulier uw ingediend. ";
	echo "Deze fouten verschijnen hieronder.<br /><br />";
	echo $error."<br /><br />";
	echo "U moet alle velden in vullen waar een * bij staat<br /><br />";
	die();
}


if(!isset($_POST['name']) ||
	!isset($_POST['email']) ||
	!isset($_POST['comments'])) {
	died('Het spijt ons, maar er waren fout (en) gevonden met het formulier uw ingediend.');		
}

$name = $_POST['name'];
$telefoonnummer_from = $_POST['telefoonnummer'];
$email_from = $_POST['email']; 
$comments = $_POST['comments']; 

$error_message = "";

$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$name)) {
  	$error_message .= 'Er is iets mis gegaan bij het in vullen van uw naam.<br>';
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  }

  if(!eregi($email_exp,$email_from)) {
  	$error_message .= 'Er is iets mis gegaan bij het in vullen van uw email.<br>';
  }

  if(strlen($comments) < 2) {
  	$error_message .= 'Er is iets mis gegaan bij het in vullen van uw vraag.';
  }
  if(strlen($error_message) > 0) {
  	died($error_message);
  }
$email_message = "Deze vraag is gekomen:\n\n";

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

$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Tel: ".clean_string($telefoonnummer_from)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "De vraag:\n ".clean_string($comments)."\n";


$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
$feedback = 'Dank u voor het stellen van deze vraag. We zullen u zo snel mogelijk terug e-mailen.';
} 
?>

 

and this is my html code:

<!doctype html>

<html lang="en">

<head>

    <meta charset="utf-8" />

    <meta name="decription" content="moet nog vragen" />

        <meta name="keywords" content="moet ook nog vragen" />

        <title>Celcommunicatie</title>

        <link href="css/reset.css" rel="stylesheet" type="text/css"/>

        <link href="css/main.css" rel="stylesheet" type="text/css"/>

        <!--[if lt IE 9]>

<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>

<![endif]-->

    </head>

    <body>

    <div id="wrapper">

        <header>

            <h1><a href="index.html"><img src="images/logo.jpg"></a></h1>

                <ul id="nav">

                <li><a href="index.html" >Home</a></li>

                    <li><a href="wiezijnwij.html">Wie zijn wij?</a></li>

                    <li><a href="glyconutrienten.html">Glyconutriënten</a></li>

                    <li><a href="voorwie.html">Voor wie?</a></li>

                    <li><a href="veelgesteldevragen.html">Veel gestelde vragen</a></li>

                    <li><a href="lezingen.html">Lezingen</a></li>

                    <li><a href="video.html">Video</a></li>

                    <li><a href="supplementen.html">Supplementen</a></li>

                    <li id="active"><a href="contact.php">Contact</a></li>

                </ul>

            </header>

            <div id="content">

            <h2>Contact</h2>

              <p class="second"><?php echo $feedback; ?></p>

<form action="contact.php" method="post">

                    <ul>

                        <li>

                            <label for="name">Naam*:</label>

                                <input type="text" name="name" id="name" />

                          </li>

                          <li>

                            <label for="email">Email*:</label>

                                <input type="text" name="email" id="email" />

                          </li>

                          <li>

                            <label for="telefoonnummer">Telefoonnummer:</label>

                                <input type="text" name="telefoonnummer" id="telefoonnummer" />

                          </li>

                          <li>

                          <label for="comments">De vraag*:</label>

                                <textarea id="comments" name="comments" cols="42" rows="9"></textarea>

                          </li>

                          <li>

                          <input type="submit" name="Submit" value="Verzenden">

                          </li>

                      </ul>

                  </form>

                  <p class="second">

                  * Zijn vereist om in te vullen.<br>

  Wij zullen uw email uitsluitend gebruiken om u terug te mailen.

              </p>

            </div>

            <footer>

            <img src="images/footer.gif"/>

            </footer>

</div>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/252437-php-mail-function/
Share on other sites

Well to display errors without reloading the page, then you will need to use javascript. If you need to check with a database to see if there are errors, you will need to use AJAX. Otherwise, if you don't mind the same page being reloaded, then put the form processing at the top of the page with the form, surrounded by an if(isset($_POST['submit'])) statement.

 

That won't solve your problem, but it should get you started. If you want further help just say so.

 

Denno

Link to comment
https://forums.phpfreaks.com/topic/252437-php-mail-function/#findComment-1294313
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.