1

I'm getting a header error while trying to add a line of code to a sendmail script.

I'm guessing I'm using the wrong method to do this.

What's the best way to bring in data such as an email address into a sendmail script with out getting the header error?

See code below, I want to pull in the [email protected] from a .php file to all the forms on the site. But includes causes a header error.

Thanks in advance.

Code Snipet:

<?php

$sitename = "Form from test.com";

$message = "This message was sent from: $sitename\n


mail( "[email protected]", $sitename, $message, "From: [email protected]" );


  header( "Location: http://test.com/thankyou.php" );
?>
1
  • On which line are you getting the "already sent" error? Also, you have a syntax error after $message Commented Dec 17, 2010 at 1:38

1 Answer 1

1

This a common error, you might have a blank line at the end of your include so your webserver send the headers and your cannot use header('Location:') anymore.

There is few solutions

  • don't close the php tags in your headers
  • enable the output buffering on your server

The first solution would be the best in my opinion

Sign up to request clarification or add additional context in comments.

1 Comment

+1 on the not including the close tags in include files, because this is a universal solution and doesn't have any sort of unpredictable consequences. It is, IMHO, a best practice when working with code-only files in PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.