SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Landing page after sending an email - refresh issue

    Hello Everyone,

    I have a question about landing page after sending an email with PHP.
    If somebody can give a bit of advice, I would really appreciate.

    What I am doing:

    Page1: Html layout with form to request info to send. "Send button" calling
    Page2.php to send the email.

    Page2.php: With the variables collected from the form,
    1) prepare the email,
    2) send the email
    3) display if everything was fine or not, kind of:

    if(!$mail->Send())
    {
    echo "There was an error sending the message";
    exit;
    }
    else
    {
    echo "Message was sent to...";
    exit;
    }

    Page2 is also currently the "landing" page after sending the email in the
    regular format of the website (layout, menu, etc...)

    Ok, now my problem is the following.

    If on Page2 the user hits the browser "refresh" button, the email is sent
    again and again, etc...
    Is there a way that I can control this?

    An acceptable behaviour for me would be to refresh the "landing" page with
    the resulting message but not to send again the message.

    What I am thinking:

    Page1: Html layout with form to request info to send. "Send button" calling
    Page2.php to send the email.

    Page2.php: With the variables collected from the form,
    1) prepare the email, (server side)
    2) send the email, (server side)
    3) call a new landing page with only the result of the process Page3.html
    (server side)
    4) only result is displayed (client side)

    Now if somebody press "Refresh" on Page3, it will not resend the email.
    Same thing if somebody press "Previous Page", he will get only the form on
    the client side.

    The question is how would you call in PHP the resulting page3 after sending
    the email?
    Or how would you do solve this issue in general?

    Thanks
    Gilbert

  2. #2
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that is what you want to do, use the following example:

    PHP Code:
    header ("Location: http://example.com/page3.php"); 

  3. #3
    SitePoint Addict
    Join Date
    Sep 2004
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it without the page3 like this

    if(!$mail->Send())
    {
    header("Location: http://example.com/page2.php?sent=false");
    exit;
    }
    else
    {
    header("Location: http://example.com/page2.php?sent=true");
    exit;
    }

    and at the top of the page check for the sent variable in order to display the proper message

    (isset($_GET['sent']) && $_GET['sent'] == "false") ? "There was an error sending the message" : "Message was sent to...";

  4. #4
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya this is good acid24ro.....
    Where there is a will there is a way
    ArunKumar

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, cool, thanks a lot.

    Gilbert
    Gilbert

  6. #6
    SitePoint Addict Shockt's Avatar
    Join Date
    Jan 2005
    Location
    California
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by acid24ro
    You can do it without the page3 like this

    if(!$mail->Send())
    {
    header("Location: http://example.com/page2.php?sent=false");
    exit;
    }
    else
    {
    header("Location: http://example.com/page2.php?sent=true");
    exit;
    }

    and at the top of the page check for the sent variable in order to display the proper message

    (isset($_GET['sent']) && $_GET['sent'] == "false") ? "There was an error sending the message" : "Message was sent to...";
    You could actually combine the whole thing in a single page using conditional statements.

  7. #7
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, but now I have another problem, I still would like to POST some data to the landing page (with some content coming from the form) - data not transmitted on the url when calling the landing page.
    Can I simulate the POST action of a form in my PHP script sending the message - and giving the hand to the landing page?

    To recap:

    1) Page1.htm (form) calling Page2.php
    2) Page2.php - only a PHP script on the server side
    Collect POST from form of Page1.htm
    Prepare email
    Send email

    Call Page3.php for landing after email while transmitting POST data to Page3.php
    3) Page3.php
    Collect POST from Page2.php
    Display what is necessary

    On the client side, we see only Page1.htm - result of Page3.php

    New question is: how can Page2.php can send POST data (without a form) to Page3.php?
    Gilbert

  8. #8
    SitePoint Addict Shockt's Avatar
    Join Date
    Jan 2005
    Location
    California
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, unless you hit the submit button on a form, POST information cannot be transfered. You can use GET or SESSION variables to transfer information from page2 to page3 but you will not be able to use POST.

  9. #9
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, I would say your best bet would be to use MySQL or sessions. Personally I would use MySQL so that I could keep records at the same time depending on what this is being used for.

  10. #10
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well in my opinion your script is all wrong. I would put all three pages in the same script. Secondly they are not pressing the refresh button, they are pressing the form button twice (or more) in a row. On my pages I have a javascript action which on pressing the submit button removes the form and replaces it with a notice that says please be pacient while your details are processed.

    With your model with the separate landing page they can still keep pressing the submit button (resetting the request) up until the last page loads. With my method that is not possible.

  11. #11
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks for all the answers.
    I still did not manage to find my perfect match for the moment and I would prefer if I could as the concept will be used through various of my current applications.

    I found this interested article (http://www.zend.com/zend/spotlight/mimocsumissions.php) which explains how to simulate POST transfer of data without forms. Not sure where I get it wrong but it is still not working fine for me, but it might be useful for some of you.

    bokehman, could you send me if possible your example, I would really appreciate. If you want to do it privately here is a possible email address (gguerin@hotmail.com).

    For the refresh button, it is just because on a specific client application, somebody just plays with it all the time, and it is obviously annoying everybody else...
    Gilbert

  12. #12
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We didn't say it wasn't possible to send POST data from PHP, just not in the way you want. You can't carry data from the form to the php page to the next page. That example you referred to with the link is to just send POST data from one page to another site or page, but it doesn't take you to that page with the data.

    It is like how the PayPal IPN works. PayPal will send you some POST data and then you have to connect back to them to give them some data back as well.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •