Avatar of MirageSF
MirageSF
 asked on

php header function probs

<?php
$mailadres="anyoldemail.com";
$subject="";
$from ="From: \"DOMAIN.COM\" <support@DOMAIN.com> ";
$body="";
mail($mailadres,$subject,$body,$from);
header( "Location: http://www.where_you_want_to_go.com/" );
exit;
?>

Hi, im using the above code to forward to 2checkout.com for order processing, a form of variables is taken before this page, and the variables work fine, the email is sent correctly etc, but once the header bit executes to the 2checkout site the variables are no longer existed, I know they work fine as I set the form to send directly to 2checkout and it works, I can also get the above to email me form contents, but for some reason they are gone once the header is executed, any ideas ?

Regards
PHP

Avatar of undefined
Last Comment
Steves2001

8/22/2022 - Mon
carchitect

try using javascript
write this after php code

<SCRIPT LANGUAGE="JavaScript">
<!--
self.location.href="filename.php";
//-->
</SCRIPT>
Jonza

you have headers allready set somewhere.
is that the only script in the file?
then the only possibility is to use javascript:
i'd do it like this:
 
<?php
$mailadres="anyoldemail.com";
$subject="";
$from ="From: \"DOMAIN.COM\" <support@DOMAIN.com> ";
$body="";
mail($mailadres,$subject,$body,$from);
print("<script type='text/javascript'>window.location='http://whatever.com';</script>");
exit;
?>
Jonza

no wait..
you don't need that exit;
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
VGR

yes, true for the exit; but it's definitely cleaner.
The problem may come from the absence of session_start(); at the beginning of the PHP script ;-)

Anyway, the browser's window where this script executes will indeed "lose" the variable contents, but you should not care as it is a redirection. The remote server doesn't session_start() or share data with you :D :D

If this can be of any help, I suggest writing a javascript snippet (easy) that opens a new window, sends to data via redirection [spawning an other window), and closes itself.

Anyway, you can't expect a redirected window to still hold YOUR server's values. So you have to make the redirection harmless to YOUR work flow
MirageSF

ASKER
I need it to pass the variables because I take the data via my form and pass it to 2checout.com who takes credit card details etc, but includes data i sent it, but inbetween all this I need it to send me an email once submit is clicked before it forwards to 2checkout
carchitect

hey javascript is not a bad option to send your variables...
another option is to include your file with include function..

like

<?
mail code

include 'filename.php';
exit;
?>

regards
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
MirageSF

ASKER
Ok, another way ive thought instead of passing the form to another page to send the email, then onto the payment system... this routine checks the form to make sure its completed, the php code below it needs to be inserted into this java so that if all is valid the php code is executed, if this is possible !

The idea is if the form is valid to send me an email to confirm details, it then automatically goes to the next site for credit card etc, idea of using php is to hide this email stuff from the browser

<script language="JavaScript" type="text/javascript">
function check_form ()
{
  valid = true; // assume valid
  if (document.form1.fullname.value.length == 0)
        { valid = false; alert('Full Name Required');
        document.form1.fullname.focus(); return false; }

  if (document.form1.email.value.length == 0)
        { valid = false; alert('Contact Email Required');
        document.form1.email.focus(); return false; }

  if (document.form1.street_address.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.street_address.focus(); return false; }

  if (document.form1.city.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.city.focus(); return false; }

  if (document.form1.state.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.state.focus(); return false; }

  if (document.form1.zip.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.zip.focus(); return false; }

  if (document.form1.country.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.country.focus(); return false; }

  if (document.form1.domain.value.length == 0)
        { valid = false; alert('Domain Name Required');
        document.form1.domain.focus(); return false; }


  if (document.form1.checkbox.checked == false )
        { valid = false; alert('You must agree to terms & conditions!');
        document.form1.checkbox.focus();return false; }
}
</script>


>>> PHP

<?php
$mailadres="sales@xcensus.com";
$from ="From: \"$email\" <$email> ";
$subject = "HOSTING PLAN ORDER: XS-PREMIUM";
$body="
HOSTING PLAN ORDER: XS-PREMIUM

CLIENTS NAME: $fullname

CONTACT EMAIL: $email

DOMAIN: $domain

CLIENTS ADDRESS: $street_address, $city, $state, $zip, $country
";
mail($mailadres,$subject,$body,$from);
?>


baeuml

Are you looking for something like

header ("Location: http://www.somedomain.com?var1=content&var2=content");

??

Steves2001

Does the page expect only post form information or will it accept get if so just append your data to the url using standard get syntax (might have to urlencode).

Just a suggestion
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
MirageSF

ASKER
No, I just need to execute that code somewhere within that java code, so if all is TRUE then execute that bit of PHP not sure on correct syntax to do that tho
ASKER CERTIFIED SOLUTION
Steves2001

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.