Jump to content

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


PhilKewley
 Share

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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 😖

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.