/    Sign up×
Community /Pin to ProfileBookmark

Headers already sent error on redirect

The below form works just fine but instead of echoing “Your E-mail has been sent” on the same page, I would like to redirect the user to a thankyou.html page instead. I have tried to do a redirect with ob_start/ob_flush to get around the “headers already sent error” but I didnt do that correctly. Any ideas on proper syntax here?

[CODE]<html>

<body>

<?php if (isset($_REQUEST[’email’]))
//if “email” is filled out, send email
{
//send email
$email = $_REQUEST[’email’] ;
$subject = $_REQUEST[‘subject’] ;
$message = $_REQUEST[‘message’] ;
mail(“[email protected]”, $subject,
$message, “From:” . $email);
echo “Your E-mail has been sent”;
}
else
//if “email” is not filled out, display the form
{
echo “<form method=’post’ action=’mailform.php’>
Email: <input name=’email’ type=’text’ /><br />
Subject: <input name=’subject’ type=’text’ /><br />
Message:<br />
<textarea name=’message’ rows=’15’ cols=’40’>
</textarea><br />
<input type=’submit’ />
</form>”;
}
?>

</body>
</html>[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@masterwinJun 19.2012 — add ob_start(); at the start of the page
×

Success!

Help @Schmit43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...