Jump to content

I am trying to get a user name from email form into a html thanks message


Recommended Posts

Hi I built a really simple customer review form https://kickasssoftwear.uk/dev/reviews.html (it's only been optimised for mobile view so far) and it works using the php mail script on this page https://kickasssoftwear.uk/dev/empty2.php - the emails are being sent to me and the format of the emails is OK, and the form redirects to the empty2 page with a mailsent message in the address bar.

I know I can leave that page as is and write a nice thank you message in the html - but what I really want to do is have the customers name there too, Thanks 'name' your review has been sent,

but I can't get it to work - it's been 4 whole days now and I really need to eat & sleep! Please if anyone has suggestions or advice for a noob, please help. Thanks

sorry my bad, I thought rather than litter the page with wonky code it would be available from the page source - but I understand how time consuming that would be, apologies

<?php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $product = $_POST['product'];
    $rating = $_POST['rating'];
    $review = $_POST['review'];

    $mailTo = "hello@kickasssoftwear.uk";
    $headers = "Product Review from: ".$name;
    $txt = "You have received a product review from: ".$name. "\n for: ".$product. "\n rating is: ".$rating."\n review: ".$review;  

    mail($mailTo, $headers, $txt);
    header("Location: send.php?mailsend");
    }

all of that works good enough.

I am not aiming for the most robust or secure forms, because I'll be sending follow up emails to customers asking for them to review the products - whether they do or not is up to them, and it's unlikely that after being invited to do so will they spam it. And any reviews that come in from any other source (that hasn't been asked to do so) will most likely get trashed anyway because it wouldn't be a verified purchase - just saying all that before any comments about those concerns.

the page loads with ?mailsend in the search bar - but way down in the centre of the page is where I want to get a message to the customer and it's just not happening.

<div class="errorPage-container">

      <h3>Thanks <?php echo ($_POST['name']); ?>.,</h3>

        <p>Your review has been sent</p>        

    </div>

 

I am sure the problem lies with the html wrapped around the PHP tags, but I've tried so many different ways without success & I can't figure out how to output the message in PHP without the need to wrap it in html 

Thanks

 

The $_POST data is only good for the page where it was submitted to. Any page you redirect to after that will not be able to see it.

If you want to output a message then do it on the page the form submitted to. Don't use a redirect for it.

thanks@requinix another clumsy error - I've been messing about this so much & I've duplicated the pages too many times - I copied and pasted the code from the original page to use in the post above, and not from the pages I had listed in the original post  - I feel really stupid for doing that - but that's lack of sleep!

this other issue is just me being clueless...

so the form on reviews.html 

  <form name="product-review" METHOD="POST" Action="empty2.php">

 

(empty2.php below)

<?php

 

if (isset($_POST['submit'])) {

    $name = $_POST['name'];

    $product = $_POST['product'];

    $rating = $_POST['rating'];

    $review = $_POST['review'];

 

    $mailTo = "hello@kickasssoftwear.uk";

    $headers = "Product Review from: ".$name;

    $txt = "You have received a product review from: ".$name. "\n for: ".$product. "\n rating is: ".$rating."\n review: ".$review;  

 

    mail($mailTo, $headers, $txt);

    header("Location: empty2.php?mailsend");

    }

 

and then I want the greeting to be on empty2.php (I'll change the name as the site develops) 

   <div class="errorPage-container">
      <h3>Thanks <?php echo ($_POST['name']); ?>.,</h3>
        <p>Your review has been sent</p>        
    </div>

Thanks

I don't understand what your post is supposed to mean. Isn't that the same code as before? My reply is the same: you can't use $_POST after a redirect so put the message on the same page instead of redirecting.

still not getting it

the form on reviews.html posts to empty2.php - the PHP code for sending the email is on empty2.php, and when the email has been sent ?mailsend is appended to the address bar of empty2.php - so I thought that I could use the $name variable in the html of empty2.php

Are you saying that the success message has to be on the same page as the form?

Honestly, I give up - if anyone can recommend PHP tutorials or suggested reading that's simple to understand and not overly technical - please let me know. Thanks

 

17 minutes ago, PhilKewley said:

the form on reviews.html posts to empty2.php - the PHP code for sending the email is on empty2.php, and when the email has been sent ?mailsend is appended to the address bar of empty2.php - so I thought that I could use the $name variable in the html of empty2.php

You are doing a redirect. You cannot use $_POST after a redirect. That's the rule.

Remove the redirect and do whatever logically follows from that.

@requinix thanks for your assistance - Although it's still unclear to me, I get what you're saying but I have no idea how to put it together.

I've wasted too much time already and I need to get the site live. So I'll just put a generic message on the page and sometime in the future I'll find the resources and learn how to do it properly. You've inspired me to learn more, just not today 😖

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.