Title: Problem with PHP Header() url
Last modified: August 20, 2016

---

# Problem with PHP Header() url

 *  Resolved [floyd8981](https://wordpress.org/support/users/floyd8981/)
 * (@floyd8981)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-php-header-url/)
 * My apologies if this is posted elsewhere, but I have searched for a while and
   cannot find a resolution.
 * I have a contact form where the action is to call a php script using the post
   method. The php script is named phpmailer2.php. This works fine, the email is
   sent, and then I would like to send the user back to the contact page with a 
   parameter in the URL (i.e. ?page-id=19&success=YES).
 * I am using the following php header statement to redirect the user back to the
   page:
 * `header('Location: ?pageID=19&success=YES');`
 * After the form is submitted, the header statement is executed, but the url ends
   up including the base name. So the url looks like:
 * ‘[http://estrellapalooza.com/wp/wp-content/themes/hero/](http://estrellapalooza.com/wp/wp-content/themes/hero/)**
   phpmailer2.php**?pageID=19&success=YES’.
 * Can anyone suggest a solution to removing phpmailer2.php from the url?
 * Any help is greatly appreciated.
 * Thanks,
    Rob

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [floyd8981](https://wordpress.org/support/users/floyd8981/)
 * (@floyd8981)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-php-header-url/#post-3586275)
 * Anyone have any suggestions?
 *  [ehoanshelt](https://wordpress.org/support/users/ehoanshelt/)
 * (@ehoanshelt)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-php-header-url/#post-3586276)
 * Hey, this is more of a php question than a WordPress question but the one thing
   I would make sure of that no PHP is being executed before your header statement.
   If there is, them the php header information has already been sent.
 * I would look into doing a JavaScript redirect and populate the JavaScript with
   php variable.
 *  Thread Starter [floyd8981](https://wordpress.org/support/users/floyd8981/)
 * (@floyd8981)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-php-header-url/#post-3586280)
 * Hi Eric,
 * Thanks for the response!
 * I did toy with the doing a javascript window.location redirect, but I get the
   same results. Plus, I’ve found that sending parameters using the javascript redirect
   has become a pain because of the escape characters. There is php code being executed
   before the header, but no output that would cause headers to already be sent.
 * The reason I decided to post this on the wordpress forum instead of a php forum
   is because the mailer script works fine when it’s not embedded in the wordpress
   folder. Once the scripts are run inside wordpress, it always reposts the current
   script as part of the URL.
 * I did attempt to manipulate the path by using various $_SERVER functions, but
   no matter what I do, “phpmailer2.php” is always appended to the front of my redirect
   location.
 * Should I create a wordpress function inside the functions.php file to process
   the mail and include that in my “contact” page template? I may try this if I 
   get some time this afternoon. There must be something I’m doing wrong lol. If
   not, I can’t imagine I would be the only one having this problem.
 * Thanks again for your response. I really appreciate it!
 * Cheers,
    Rob
 *  Thread Starter [floyd8981](https://wordpress.org/support/users/floyd8981/)
 * (@floyd8981)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-php-header-url/#post-3586287)
 * My apologies, but I’m doing this locally. The form that is on the site now is
   just a plugin form. I changed it back to the plugin when I realized I was having
   a problem.
 *  Thread Starter [floyd8981](https://wordpress.org/support/users/floyd8981/)
 * (@floyd8981)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problem-with-php-header-url/#post-3586294)
 * Hello,
 * I found a workaround for this issue. I’ve added the code in my php script as 
   a function in the “functions.php” file. I created a page template for my contact
   form and used a hidden field on the form to determine if the form is being posted.
   If the hidden value is set, I call the function. If not, I just display the form.
   Unfortunately, I do have to use the javascript redirect because of the header
   issue, but at least it is something I can work with.
 * Thanks,
    Rob

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problem with PHP Header() url’ is closed to new replies.

## Tags

 * [basename](https://wordpress.org/support/topic-tag/basename/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [floyd8981](https://wordpress.org/support/users/floyd8981/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/problem-with-php-header-url/#post-3586294)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
