colect data in php & redirect within if clause

Discussion in 'PHP' started by zvezda, Mar 26, 2010.

  1. #1
    Hello,
    I would apreciate any idea how to solve my problem.
    I have a form in html and than thank you in php.
    I have
    <form method="POST" name="contact information" action="thankyou.php">
    Code (markup):
    and than it sends me an email with ,,,,,,,,,,,,,,,,,,,,,,, and that's all.

    and write thank you.

    What I need is
    1. where is my mistake to get data?

    2. how to insert redirect in print function in php or some other.
    Idea is to write thank you and after 5 seconds redirect to other page.

    My thankyou.php is :
    <?php
    $to = "mail@mail.com";
    $subject = "Form contact";
    $wunsche_luftentfeuchter= $_REQUEST[‘wunsche_luftentfeuchter’];
    $wunsche_umluft_kondensationstrockner= $_REQUEST[‘wunsche_umluft_kondensationstrockner’];
    $wunsche_allwetter_schnelltrockner = $_REQUEST[‘wunsche_allwetter_schnelltrockner’];
    $e_mail = $_REQUEST[‘e_mail’];
    $zuname_und_vorname = $_REQUEST[‘zuname_und_vorname’];
    $adresse = $_REQUEST[‘adresse’];
    $telefon = $_REQUEST[‘telefon’];
    $field2 = $_REQUEST[‘field2’];
    $field3= $_REQUEST[‘field3’];
    $field4 = $_REQUEST[‘field4’];
    $field5 = $_REQUEST[‘field5’];
    $field6 = $_REQUEST[‘field6’];
    $field1 = $_REQUEST[‘field1’];
    $field7 = $_REQUEST[‘field7’];
    $field8 = $_REQUEST[‘field8’];
    
    
    
    $headers = "From: $email";
    $sent = mail ("mail@mail.com","Form contact",""$interessiere_besichtigung,$interessiere_personliche_beratung,$interessiere_mitarbeit,$wunsche_heubeluftung, $wunsche_heutrocknung, $wunsche_luftentfeuchter,$wunsche_umluft_kondensationstrockner,$wunsche_allwetter_schnelltrockner,$e_mail,$zuname_und_vorname,$adresse,$telefon,$field2,$ field3,$ field4,$ field5,$ field6,$ field1,$ field7,$ field8 ");
    if($sent)
    {
    print "Your mail was sent successfully.";
    
      }
    else
    {print "We encountered an error sending your mail"; }
    ?>
    Code (markup):

    Thank you.
     
    zvezda, Mar 26, 2010 IP
  2. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #2
    1) Use $_POST['input_name'] instead of $_REQUEST.
    2) You can't make a delayed redirect from PHP (since the output is pure HTML). So you've got two opportunities:
    2,1) Immediate redirect from PHP: <? header("Location: new_file.php"); ?> . Be sure to run this before any other output is done (or use PHP's output buffer
    2,2) Print a redirect meta-tag which can delay the redirect: <meta http-equiv="refresh" content="5;URL=new_file.php" />
     
    elias_sorensen, Mar 26, 2010 IP
  3. zvezda

    zvezda Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you for you reply
    1. I use post and still no data come to email
    2. for a redirect I use 2.1 it redirects, but it redirects if email is sent or not.

    Do you have any other idea what need to be chenge to get a data

    cheers
     
    zvezda, Mar 26, 2010 IP
  4. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    instead of sending the mail, for testing just print the output. (also note that you have errors(spaces) in this code at ($ field3,$ field4,$ field5,$ field6,$ field1,$ field7,$ field8 )
    
    $sent = mail ("mail@mail.com","Form contact",""$interessiere_besichtigung,$interessiere_personliche_beratung,$interessiere_mitarbeit,$wunsche_heubeluftung, $wunsche_heutrocknung, $wunsche_luftentfeuchter,$wunsche_umluft_kondensationstrockner,$wunsche_allwetter_schnelltrockner,$e_mail,$zuname_und_vorname,$adresse,$telefon,$field2,$ field3,$ field4,$ field5,$ field6,$ field1,$ field7,$ field8 ");
    
    to
    
     echo ("$interessiere_besichtigung,$interessiere_personliche_beratung,$interessiere_mitarbeit,$wunsche_heubeluftung, $wunsche_heutrocknung, $wunsche_luftentfeuchter,$wunsche_umluft_kondensationstrockner,$wunsche_allwetter_schnelltrockner,$e_mail,$zuname_und_vorname,$adresse,$telefon,$field2,$ field3,$ field4,$ field5,$ field6,$ field1,$ field7,$ field8 ");
    
    PHP:
    2. for a redirect I use 2.1 it redirects, but it redirects if email is sent or not.

    Well obviously place the meta redirect in the if statement you got there...
     
    pig2cat, Mar 27, 2010 IP
  5. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The mistake in your script is quite obvious... the variables you put in the email string are empty. For example, "$interessiere_besichtigung" is empty, because you never gave it a value within your code.

    Telling from your variable names, you are german - I'm also german. If you'd like to speak German instead of English feel free to PM me.
     
    ThomasTwen, Mar 27, 2010 IP
  6. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Check the name and id attributes of the form elements.

    Example:
    <input type="text" id="field2" name="field2">
    
    Code (markup):
    if this not solve please provide the HTML form code here <form>...</form>.
     
    mnvlxxx, Mar 27, 2010 IP