Form in HTML Email Not Posting Data

2019-08-03 05:15发布

问题:

I have this question about why my form is not posting data to my PHP script. To unsubscribe from an emailing list I've set up, I send the user that has unsubscribed an email with a form that posts some data.

<html>
<body>
<div>
    <p>This is a confirmation message to confirm that you unsubscribed from the sci-eng email list.</p>
    <p>Click on the button below to confirm your unsubscription.</p>
    <form id="unsubform">
        <div class="form-in">
            <input type="hidden" id="emailkey" name="emailkey" value="key">
            <input type="hidden" id="email" name="email" value="email@domain.com">
            <button class="btn" id="submit" type="submit" formaction="http://redlinks.ca/sci-eng/db/unsubscribe.php" formmethod="post">Unsubscribe</button>
        </div>
    </form>
    </div>
    </body>
</html>

When on the page that the form is POSTed to, I get the "no data" error that I have set up if there is no data in the $_POST["email"] variable. I have tried using var_dump($_POST), but that just returns with array(0) { } and that isn't working for me.

The thing that confuses me the most is when I copy the exact html from the email, and paste it into a blank page, when I click on submit/unsubscribe it posts the data just fine, and elsewhere on my site I have the exact same script, the only different being the formaction is without the /db in it. The page that one is sent to behaves how it should, showing the propper array of data instead of nothing. That's the only difference.

If it makes any difference, I use Thunderbird for Windows 10 as my email client.

Anyone who thinks they can help would be appreciated :)

回答1:

Due to security issues forms are not supported and not recommended within emails. Most of email clients will warn the user of a risk or simply will disable it and it will not work, like in your case.

The best practice for enabling unsubscribing is by using a link. You can pass any requierd parameter for unsubscribing on the link, for example http://www.example.com/unsubscribe.php?usermail=mail@gmail.com.



回答2:

TRY WITH:

<html>
<body>
<div>
    <p>This is a confirmation message to confirm that you unsubscribed from the sci-eng email list.</p>
    <p>Click on the button below to confirm your unsubscription.</p>
    <form id="unsubform" action="http://redlinks.ca/sci-eng/db/unsubscribe.php" method="post">
        <div class="form-in">
            <input type="hidden" id="emailkey" name="emailkey" value="key">
            <input type="hidden" id="email" name="email" value="email@domain.com">
            <button class="btn" id="submit" type="submit">Unsubscribe</button>
        </div>
    </form>
    </div>
    </body>
</html>


回答3:

IF you won't use POST method so how your form values could be posted to phpScript. Try the following code.

<html>
<body>
<div>
<p>This is a confirmation message to confirm that you unsubscribed 
   from the sci-eng email list.</p>
<p>Click on the button below to confirm your unsubscription.</p>
<form id="unsubform" method="POST" action="http://redlinks.ca/sci-eng/db/unsubscribe.php">
    <div class="form-in">
    <input type="hidden" id="emailkey" name="emailkey" value="key">
    <input type="hidden" id="email" name="email" value="email@domain.com">         
    <button class="btn" id="submit" type="submit" >Unsubscribe</button>
    </div>
</form>
</div>
</body>



回答4:

The default method is GET, not POST; you need to specify

<form method="post" ...>

Maybe a link to this form hosted online might be a better idea; some mail clients do not support showing mails; and maybe more clients might refuse to submit or post them due to security concerns (e.g. webmail interfaces).



回答5:

Do not send form for confirmation.Try these steps :

  1. Generate unique encrypted key for those email who unsubscribe and store in database

  2. Send confirmation link to particular user email with key as (http://domainurl/confirm.php?key=1533c67e5e70ae7439a9aa993d6a3393)

  3. Now check key for corresponding email and unsubscribe and also remove key from database