Headers issue

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Sat Jun 11, 2011 3:16 am

Hello guys,

I'm new here. I'm Nino van den Bosch, a Dutch 13-year old guy.
I'm owning my 'learning-'website http://www.ninovdbosch.com

Right now, and that will occure often more, I've a question.
My site is having a browser warning script, a contactform and a guestbook. (the browser warning script is just for learning, I know it's user-unfriendly!)
Now, if I want to send an e-mail with the contact form, or if I want to post a post in my guestbook I have a script that sets a cookie, to prevent flooding.

With my previous (free) (000-)webhost it wasn't a problem but right now it is:
I can't send a header if the page is already downloaded. So, I can't set a cookie after a post.

My question is now: what can I do, to have the same "system", but not an error?

My code:

Code: Select all

<?php
if (isset($_POST['submit'])) {
    if (isset($_COOKIE['contact'])) {
        $melding .= "<p><strong>U mag maar één keer in de vijf minuten een bericht versturen. Dit is om misbruik te voorkomen.</strong></p>";
        echo $melding;
    }else{
    
    $naam = $_POST['naam'];
    $mail = $_POST['mail'];
    $onderwerp = $_POST['onderwerp'];
    $bericht = $_POST['bericht'];
    $ip = $_SERVER['REMOTE_ADDR']; 
    $melding = "";
    $error = FALSE;
    $ontvanger = "mail@ninovdbosch.com";
    $verzonden = FALSE;

$naam = strip_tags($naam);
$mail = strip_tags($mail);
$onderwerp = strip_tags($onderwerp);
$bericht = strip_tags($bericht);


if (strlen($naam) < 3) {
    $melding .= "<strong>U heeft geen naam ingevuld.</strong><br />";
    $error = TRUE;
}    
if (strlen($mail) < 1) {
    $melding .= "<strong>U heeft geen e-mailadres ingevuld.</strong><br />";
    $error = TRUE;
}elseif(!preg_match('~^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$~i', $mail)) {
    $melding .= '<strong><span class="pink">' . $mail . '</span> is geen geldig e-mailadres, vul een geldig e-mailadres in.</strong><br />';
    $error = TRUE;
}
if (strlen($onderwerp) < 3) {
    $melding .= "<strong>U heeft geen onderwerp ingevuld.</strong><br />";
    $error = TRUE;
}

if (strlen($bericht) < 1) {
    $melding .= "<strong>U heeft geen bericht ingevuld.</strong><br />";;
    $error = TRUE;
}elseif(strlen($bericht) <10) {
    $melding .= "<strong>Uw bericht bevat te weinig tekens.</strong><br />";
    $error = TRUE;
}

if (($error) == TRUE) {
    $melding .= "<br />";
    echo $melding;
}else{
    $headers = "From: \"$naam\" <$mail>\r\n";
    $headers .= "Reply-To: \"$naam\" <$mail>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $onderwerp = "Contactformulier: $onderwerp";
    $tekst = "U heeft een bericht ontvangen via uw contactformulier op uw website.";
    $tekst .= "\r\n\rDoor: $naam";
    $tekst .= "\r\nE-mail: $mail";
    $tekst .= "\r\nIP-adres: $ip";
    $tekst .= "\r\n\r\n<strong>Bericht:</strong>\r\n $bericht";
    
    $tekst = nl2br($tekst);
    
if (mail($ontvanger, $onderwerp, $tekst, $headers)) {
    $melding = "<p><strong>Uw e-mail is met succes verzonden.</strong></p><br />";
        setcookie("contact", "send", time()+300, "/");
    $verzonden = TRUE;
    echo "<p>" . $melding . "</p>";
}else{
    $melding = "<p>Er is een probleem opgetreden. Probeer het alstublieft opnieuw.</p><br />";
    $verzonden = FALSE;
    echo "<p>" . $melding . "</p>";
}
}
}
}
?>


<form action="/contact.php" method="post">
<table>
<tr>
<td width="150px">Naam</td><td><input type="text" name="naam" style="width:250px;" value="<? echo htmlentities($_POST['naam']);?>" /></td>
</tr>
<tr>
<td width="150px">E-mail</td><td><input type="text" name="mail" style="width:250px;" value="<? echo htmlentities($_POST['mail']);?>" /></td>
</tr>
<tr>
<td width="150px">Onderwerp</td><td><input type="text" name="onderwerp" style="width:250px;" value="<? echo htmlentities($_POST['onderwerp']);?>" /></td>
</tr>
</table>
<br />
<table>
<tr><td>Bericht</td></tr>
<tr>
<td><textarea name="bericht" rows="10" style="width:490px;"><? echo htmlentities($_POST['bericht']);?></textarea></td>
</tr>

<tr><td><input type="submit" name="submit" value="Verzenden" style="float:right; margin-top:10px; padding:5px; font-weight:none;" /></td></tr>

</table>
</form>
  <p>Met het contactformulier kunt u contact met mij opnemen.
  Dit zal gebeuren via e-mail.
  Bij het verzenden gaat u akkoord met het feit dat uw gegevens worden verzonden. Deze zullen niet aan derden worden verstrekt. Ook verzoek ik u vriendelijk het formulier niet te misbruiken.
  </p>
The part of the code which is important:

Code: Select all

if (mail($ontvanger, $onderwerp, $tekst, $headers)) {
    $melding = "<p><strong>Uw e-mail is met succes verzonden.</strong></p><br />";
        setcookie("contact", "send", time()+300, "/");
    $verzonden = TRUE;
    echo "<p>" . $melding . "</p>";
} 
Well, I hope somebody can help me! ;)

Greetings,
Nino van den Bosch

P.S. I'm Dutch, please forgive me my grammar/words mistakes.
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Mon Jun 13, 2011 2:20 am

Anyone? Please?
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Mon Jun 13, 2011 3:00 am

What kind of the error did you get?
johnj
php-forum GURU
php-forum GURU
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Mon Jun 13, 2011 3:20 am

You need to set the cookie before anything is output to the browser.
ravisoni6262
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Jun 13, 2011 4:08 am

Mon Jun 13, 2011 4:30 am

HTTP header need to set up earlier before any output has been sent by scipt and cookie can be set from any where of the script this could be help ful to you this often a problem of newbie please reach at my blog on PHP which is http://php-mechanic.blogspot.com
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Mon Jun 13, 2011 8:52 am

The error I'd get:
Warning: Cannot modify header information - headers already sent by (output started at /home/ninovdbo/public_html/contact.php:7) in /home/ninovdbo/public_html/contact.php on line 116
But there is a misunderstanding:
I'll understand an header (cookie) can only be send WITH the whole page response.
But how do I fix this, such that after the succesful page a cookie can be set?

^That is my question.
johnj
php-forum GURU
php-forum GURU
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Mon Jun 13, 2011 9:10 am

One way to try will be:
You will set the cookie and then do a redirect to another page using header(). On that page you will display whatever message you want into (including....maybe even the echo of $melding).
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Mon Jun 13, 2011 11:34 am

johnj wrote:One way to try will be:
You will set the cookie and then do a redirect to another page using header(). On that page you will display whatever message you want into (including....maybe even the echo of $melding).
No, what I can do is to redirect - not using header() - the user after the form completion to another page and set the cookie from there.

A better option is probably to include a page:

Code: Select all

if (mail($ontvanger, $onderwerp, $tekst, $headers)) {
    $melding = "<p><strong>Uw e-mail is met succes verzonden.</strong></p><br />";
        include 'setcookie.inc.php';
    $verzonden = TRUE;
    echo "<p>" . $melding . "</p>";
}  
setcookie.inc.php

Code: Select all

setcookie("contact", "send", time()+300, "/");
 

Is this possible? I'll try this soon! ;)
johnj
php-forum GURU
php-forum GURU
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Mon Jun 13, 2011 5:58 pm

I am not optimistic that this solution will work - anyway, try!
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Tue Jun 14, 2011 7:00 am

Warning: Cannot modify header information - headers already sent by (output started at /home/ninovdbo/public_html/gastenboek.php:7) in /home/ninovdbo/public_html/overig/setcookie_gb.inc.php on line 2
It Didn't work. Anybody got an idea?
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Tue Jun 14, 2011 7:52 am

Please give the full code to understand whats happens. Thank you.
johnj
php-forum GURU
php-forum GURU
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Tue Jun 14, 2011 8:09 am

You can try the following:

a). set the cookie before this line:if (mail($ontvanger, $onderwerp, $tekst, $headers)) {
b). or, set the cookie as you are doing right now and then do a redirect.
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Tue Jun 14, 2011 8:55 am

@Johnj

a. That will not be a good idea, because the cookie only must be set AFTER the mail is send.
b. A redirect is not too bad, but that is my last opportunity. I'll want to avoid it first, because a redirect not anymore is according the IF.

@Suhoij
Well, the full code is in my first post. ;)
But that's only the PHP. Here's the other part (header/footer etc. included)

Code: Select all

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nino van den Bosch &bull; Contact</title>
<link rel="shortcut icon" type="image/x-icon" href="/styles/images/favicon.ico" />
<link href="/styles/layout.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<?php
if (!isset($_COOKIE["browse"])){
?>
<script language="JavaScript">
window.location = "/errors/browserwarning.php"
</script>
<?php
}
?>
<![endif]-->
</head>

<body>

<div class="container">
<div class="header"></div>
<div class="menubar">
<ul>
    <li><a href="/index.php" class="menulink">Home</a></li>
    <li><a href="/natech" class="menulink">Natech</a></li>
    <li><a href="/about.php" class="menulink">Over mij</a></li>
    <li><a href="/news.php" class="menulink">Nieuws</a></li>
    <li><a href="/gastenboek.php" class="menulink">Gastenboek</a></li>
    <li><a href="/contact.php" class="menulinkopen">Contact</a></li>
</ul>
</div>
<div class="sidebar">
<strong><a href="/natech/index.php" class="natechlink">Natech</a></strong>
<br /><a href="/natech/project1.php" class="natechlink">- Spuitsjabloon</a>
<br /><a href="/natech/project2.php" class="natechlink">- Houten letter</a>
<br /><a href="/natech/project3.php" class="natechlink">- Technische tekening</a>
<br /><a href="/natech/project4.php" class="natechlink">- TWIK</a>
<br /><a href="/natech/project5.php" class="natechlink">- Lampjes op een plankje</a>
<br /><a href="/natech/project6.php" class="natechlink">- Speaker</a>
<br /><a href="/natech/project7.php" class="natechlink">- Perspex</a>
<br /><a href="/natech/project8.php" class="natechlink">- Grijper</a>
</div>
<div class="content">

<h3><span class="green">Nino</span> <span class="pink">van den Bosch</span> - Contact</h3>

<?php
if (isset($_POST['submit'])) {
    if (isset($_COOKIE['contact'])) {
        $melding .= "<p><strong>U mag maar één keer in de vijf minuten een bericht versturen. Dit is om misbruik te voorkomen.</strong></p>";
        echo $melding;
    }else{
    
    $naam = $_POST['naam'];
    $mail = $_POST['mail'];
    $onderwerp = $_POST['onderwerp'];
    $bericht = $_POST['bericht'];
    $ip = $_SERVER['REMOTE_ADDR']; 
    $melding = "";
    $error = FALSE;
    $ontvanger = "mail@ninovdbosch.com";
    $verzonden = FALSE;

$naam = strip_tags($naam);
$mail = strip_tags($mail);
$onderwerp = strip_tags($onderwerp);
$bericht = strip_tags($bericht);


if (strlen($naam) < 3) {
    $melding .= "<strong>U heeft geen naam ingevuld.</strong><br />";
    $error = TRUE;
}    
if (strlen($mail) < 1) {
    $melding .= "<strong>U heeft geen e-mailadres ingevuld.</strong><br />";
    $error = TRUE;
}elseif(!preg_match('~^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$~i', $mail)) {
    $melding .= '<strong><span class="pink">' . $mail . '</span> is geen geldig e-mailadres, vul een geldig e-mailadres in.</strong><br />';
    $error = TRUE;
}
if (strlen($onderwerp) < 3) {
    $melding .= "<strong>U heeft geen onderwerp ingevuld.</strong><br />";
    $error = TRUE;
}

if (strlen($bericht) < 1) {
    $melding .= "<strong>U heeft geen bericht ingevuld.</strong><br />";;
    $error = TRUE;
}elseif(strlen($bericht) <10) {
    $melding .= "<strong>Uw bericht bevat te weinig tekens.</strong><br />";
    $error = TRUE;
}

if (($error) == TRUE) {
    $melding .= "<br />";
    echo $melding;
}else{
    $headers = "From: \"$naam\" <$mail>\r\n";
    $headers .= "Reply-To: \"$naam\" <$mail>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $onderwerp = "Contactformulier: $onderwerp";
    $tekst = "U heeft een bericht ontvangen via uw contactformulier op uw website.";
    $tekst .= "\r\n\rDoor: $naam";
    $tekst .= "\r\nE-mail: $mail";
    $tekst .= "\r\nIP-adres: $ip";
    $tekst .= "\r\n\r\n<strong>Bericht:</strong>\r\n $bericht";
    
    $tekst = nl2br($tekst);
    
if (mail($ontvanger, $onderwerp, $tekst, $headers)) {
    $melding = "<p><strong>Uw e-mail is met succes verzonden.</strong></p><br />";
        setcookie("contact", "send", time()+300, "/");
    $verzonden = TRUE;
    echo "<p>" . $melding . "</p>";
}else{
    $melding = "<p>Er is een probleem opgetreden. Probeer het alstublieft opnieuw.</p><br />";
    $verzonden = FALSE;
    echo "<p>" . $melding . "</p>";
}
}
}
}
?>


<form action="/contact.php" method="post">
<table>
<tr>
<td width="150px">Naam</td><td><input type="text" name="naam" style="width:250px;" value="<? echo htmlentities($_POST['naam']);?>" /></td>
</tr>
<tr>
<td width="150px">E-mail</td><td><input type="text" name="mail" style="width:250px;" value="<? echo htmlentities($_POST['mail']);?>" /></td>
</tr>
<tr>
<td width="150px">Onderwerp</td><td><input type="text" name="onderwerp" style="width:250px;" value="<? echo htmlentities($_POST['onderwerp']);?>" /></td>
</tr>
</table>
<br />
<table>
<tr><td>Bericht</td></tr>
<tr>
<td><textarea name="bericht" rows="10" style="width:490px;"><? echo htmlentities($_POST['bericht']);?></textarea></td>
</tr>

<tr><td><input type="submit" name="submit" value="Verzenden" style="float:right; margin-top:10px; padding:5px; font-weight:none;" /></td></tr>

</table>
</form>
  <p>Met het contactformulier kunt u contact met mij opnemen.
  Dit zal gebeuren via e-mail.
  Bij het verzenden gaat u akkoord met het feit dat uw gegevens worden verzonden. Deze zullen niet aan derden worden verstrekt. Ook verzoek ik u vriendelijk het formulier niet te misbruiken.
  </p>
</div>
<div class="footer">
                                 &copy; Nino van den Bosch
<?php 
$tijd = time () ;
$beginjaar = 2010 ;
$jaar = date("Y",$tijd) ; 
echo $beginjaar . " - " . $jaar;
?> 
</div>

</div>
</body>
</html>
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Tue Jun 14, 2011 9:28 am

Ok only one thing you must to do - is recode your script that setcookie appears in first line of your page. Take all php code and put it before DOCTYPE. Instead of echo the strings - save them and then echo wherever you want.
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Tue Jun 14, 2011 9:30 am

Or the second way is using buffer. Read about ob_start, ob_get_contents. This functions can help you.
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Wed Jun 15, 2011 7:20 am

Option 1:
That isn't such a good idea. I think I can't code that in a way that it works like an echo.

Option 2:
Wow, that is an great solution!
But how to combine this with Setcookie (Can't find anything on the web what is about this)
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Wed Jun 15, 2011 7:27 am

You don't need something specific - just start buffering on page start and echo buffer content on page end. But I would preffer first case - it is more natural way ( true way).
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Wed Jun 15, 2011 7:37 am

Ok, I'll want to try it, but I have no experience with having a code on (one of) my first rows which is executed later. How to do that?
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Wed Jun 15, 2011 7:53 am

Put <?php ob_start(); ?> in the header file in the first line. Then put <?php echo ob_get_flush(); ?> to the last line of the footer.
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Wed Jun 15, 2011 9:17 am

http://ninovdbosch.com/contact.php

Code:

Code: Select all

<?php ob_start(); ?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nino van den Bosch &bull; Contact</title>
<link rel="shortcut icon" type="image/x-icon" href="/styles/images/favicon.ico" />
<link href="/styles/layout.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div class="container">
<div class="header"></div>
<div class="menubar">
<ul>
    <li><a href="/index.php" class="menulink">Home</a></li>
    <li><a href="/natech" class="menulink">Natech</a></li>
    <li><a href="/about.php" class="menulink">Over mij</a></li>
    <li><a href="/news.php" class="menulink">Nieuws</a></li>
    <li><a href="/gastenboek.php" class="menulink">Gastenboek</a></li>
    <li><a href="/contact.php" class="menulinkopen">Contact</a></li>
</ul>
</div>
<div class="sidebar">
<strong><a href="/natech/index.php" class="natechlink">Natech</a></strong>
<br /><a href="/natech/project1.php" class="natechlink">- Spuitsjabloon</a>
<br /><a href="/natech/project2.php" class="natechlink">- Houten letter</a>
<br /><a href="/natech/project3.php" class="natechlink">- Technische tekening</a>
<br /><a href="/natech/project4.php" class="natechlink">- TWIK</a>
<br /><a href="/natech/project5.php" class="natechlink">- Lampjes op een plankje</a>
<br /><a href="/natech/project6.php" class="natechlink">- Speaker</a>
<br /><a href="/natech/project7.php" class="natechlink">- Perspex</a>
<br /><a href="/natech/project8.php" class="natechlink">- Grijper</a>
</div>
<div class="content">

<h3><span class="green">Nino</span> <span class="pink">van den Bosch</span> - Contact</h3>

<?php
if (isset($_POST['submit'])) {
    if (isset($_COOKIE['contact'])) {
        $melding .= "<p><strong>U mag maar één keer in de vijf minuten een bericht versturen. Dit is om misbruik te voorkomen.</strong></p>";
        echo $melding;
    }else{
    
    $naam = $_POST['naam'];
    $mail = $_POST['mail'];
    $onderwerp = $_POST['onderwerp'];
    $bericht = $_POST['bericht'];
    $ip = $_SERVER['REMOTE_ADDR']; 
    $melding = "";
    $error = FALSE;
    $ontvanger = "mail@ninovdbosch.com";
    $verzonden = FALSE;

$naam = strip_tags($naam);
$mail = strip_tags($mail);
$onderwerp = strip_tags($onderwerp);
$bericht = strip_tags($bericht);


if (strlen($naam) < 3) {
    $melding .= "<strong>U heeft geen naam ingevuld.</strong><br />";
    $error = TRUE;
}    
if (strlen($mail) < 1) {
    $melding .= "<strong>U heeft geen e-mailadres ingevuld.</strong><br />";
    $error = TRUE;
}elseif(!preg_match('~^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$~i', $mail)) {
    $melding .= '<strong><span class="pink">' . $mail . '</span> is geen geldig e-mailadres, vul een geldig e-mailadres in.</strong><br />';
    $error = TRUE;
}
if (strlen($onderwerp) < 3) {
    $melding .= "<strong>U heeft geen onderwerp ingevuld.</strong><br />";
    $error = TRUE;
}

if (strlen($bericht) < 1) {
    $melding .= "<strong>U heeft geen bericht ingevuld.</strong><br />";;
    $error = TRUE;
}elseif(strlen($bericht) <10) {
    $melding .= "<strong>Uw bericht bevat te weinig tekens.</strong><br />";
    $error = TRUE;
}

if (($error) == TRUE) {
    $melding .= "<br />";
    echo $melding;
}else{
    $headers = "From: \"$naam\" <$mail>\r\n";
    $headers .= "Reply-To: \"$naam\" <$mail>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $onderwerp = "Contactformulier: $onderwerp";
    $tekst = "U heeft een bericht ontvangen via uw contactformulier op uw website.";
    $tekst .= "\r\n\rDoor: $naam";
    $tekst .= "\r\nE-mail: $mail";
    $tekst .= "\r\nIP-adres: $ip";
    $tekst .= "\r\n\r\n<strong>Bericht:</strong>\r\n $bericht";
    
    $tekst = nl2br($tekst);
    
if (mail($ontvanger, $onderwerp, $tekst, $headers)) {
    $melding = "<p><strong>Uw e-mail is met succes verzonden.</strong></p><br />";
        setcookie("contact", "send", time()+300, "/");
    $verzonden = TRUE;
    echo "<p>" . $melding . "</p>";
}else{
    $melding = "<p>Er is een probleem opgetreden. Probeer het alstublieft opnieuw.</p><br />";
    $verzonden = FALSE;
    echo "<p>" . $melding . "</p>";
}
}
}
}
?>


<form action="/contact.php" method="post">
<table>
<tr>
<td width="150px">Naam</td><td><input type="text" name="naam" style="width:250px;" value="<? echo htmlentities($_POST['naam']);?>" /></td>
</tr>
<tr>
<td width="150px">E-mail</td><td><input type="text" name="mail" style="width:250px;" value="<? echo htmlentities($_POST['mail']);?>" /></td>
</tr>
<tr>
<td width="150px">Onderwerp</td><td><input type="text" name="onderwerp" style="width:250px;" value="<? echo htmlentities($_POST['onderwerp']);?>" /></td>
</tr>
</table>
<br />
<table>
<tr><td>Bericht</td></tr>
<tr>
<td><textarea name="bericht" rows="10" style="width:490px;"><? echo htmlentities($_POST['bericht']);?></textarea></td>
</tr>

<tr><td><input type="submit" name="submit" value="Verzenden" style="float:right; margin-top:10px; padding:5px; font-weight:none;" /></td></tr>

</table>
</form>
  <p>Met het contactformulier kunt u contact met mij opnemen.
  Dit zal gebeuren via e-mail.
  Bij het verzenden gaat u akkoord met het feit dat uw gegevens worden verzonden. Deze zullen niet aan derden worden verstrekt. Ook verzoek ik u vriendelijk het formulier niet te misbruiken.
  </p>
</div>
<div class="footer">
                                 &copy; Nino van den Bosch
<?php 
$tijd = time () ;
$beginjaar = 2010 ;
$jaar = date("Y",$tijd) ; 
echo $beginjaar . " - " . $jaar;
?> 
</div>

</div>
</body>
</html>
<?php echo ob_get_flush(); ?>
It does work, but the HTML-output is displayed twice. The mail is NOT send twice! ;)
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Wed Jun 15, 2011 9:26 am

Sorry put the ob_end_flush() instead of echo ob_get_fkush().
NinovdBosch
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Jun 11, 2011 2:52 am

Wed Jun 15, 2011 10:44 am

Wow, thank you so much! ;)
Suhoij
php-forum Fan User
php-forum Fan User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Wed Jun 15, 2011 12:26 pm

you're welcome )
Post Reply