Form in HTML Email Not Posting Data - php

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 :)

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.

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>

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>

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).

Do not send form for confirmation.Try these steps :
Generate unique encrypted key for those email who unsubscribe and store in database
Send confirmation link to particular user email with key as (http://domainurl/confirm.php?key=1533c67e5e70ae7439a9aa993d6a3393)
Now check key for corresponding email and unsubscribe and also remove key from database

Related

Inline PHP Send Mail not working

PHP isn't my strength and when I was asked to implement a modal newsletter subscription popup I cringed because I knew I was going to have to use PHP. I have scoured the internet all day trying various things, but I cannot seem to get anything to work and I am really hoping that someone will be able to point me in the right direction. It is super simple, I only need a name and email address which is then sent to an account I specify. I am sure this is really basic, but with my lack of experience with PHP I am totally lost as to where I am going wrong. My code is below.
<?php
if($_POST["submit"]) {
$recipient="my#emailaddress.com";
$subject="Newsletter Subscription";
$senderName=$_POST["name"];
$senderEmail=$_POST["email"];
$mailBody="Name: $senderName\nEmail: $senderEmail\n\nThis is a test!";
mail($recipient, $subject, $mailBody, "From: $senderName <$senderEmail>");
header('Location:http://www.urltoredirect.com/');
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="sendmail.php">
<div class="rbm_input_txt">
<input type="name" name="name" placeholder="name" required>
</div>
<div class="rbm_input_txt">
<input type="email" name="email" placeholder="email" required>
</div>
<div class="rbm_form_submit">
<button type="submit" class="rbm_btn_x_out_shtr">subscribe</button>
</div>
</form>
</body>
</html>
I save the file as sendmail.php and upload to my server. When I fill out the form, the page just reloads, it isn't redirecting to the URL specified and I am not receiving any email. I suspect the issue is in the send mail and once that is sorted, the redirect will work. Can anyone see anything obvious that I am missing?
EDIT: Added the name attribute to my code as suggested below. Issue is still unresolved.
You're checking to see if $_POST['submit'] is truthy, but your form never actually sets that value. There are two changes you can make to fix this:
In order for the submit key to be present in your request, you need to assign it to a field in your form. You'll likely want to add it to the submit button, which can be done by simply adding the name parameter to your submit button:
<button name="submit" type="submit" class="rbm_btn_x_out_shtr">subscribe</button>
Even with the above change, $_POST['submit'] will still evaluate to false since its value will be empty. (You can see this in the rules for boolean conversions.) You can get around this by checking to see if its set, rather than if it's truthy:
if (isset($_POST['submit']))
Alternatively, you could just look for a different field such as name or email, since you know both of those fields will be set on submit.
there must be name in tags
<div class="rbm_input_txt"><input type="name" placeholder="name" name="name" required><input type="email" placeholder="email" name="email``" required

Two actions in a single form

I would like to say that I've already read all the similar questions, but did not find the answer I need.
So, I have the HTML form on the remote host that consists of username, password and "rememberMe" checkbox:
<form method="POST" action="http://1.2.3.4:5000/webman/login.cgi">
<p><input type="text" name="username" value="" placeholder="Username or Email"></p>
<p><input type="password" name="passwd" value="" placeholder="Password"></p>
<p class="remember_me">
<label>
<input type="checkbox" name="rememberme" id="remember_me">
Remember me on this computer
</label>
</p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
</form>
All I want to do is to submit data from one form to another one (another one - this is my Synology NAS Login form). But the problem is that if I write action="http://1.2.3.4:5000/webman/index.cgi", it does nothing (just sends me to the second login form).
But when I use action="http://1.2.3.4:5000/webman/login.cgi", it forwards me to the login.cgi page where only the following is displayed (with correct username & passwd)
{ "result" : "success", "success" : true }
BUT: if I change login.cgi to index.cgi in the browser, I go then to my desktop as I were logged in successfully via the default form.
So, on this basis, the question is:
How to send data to login.cgi, but redirect the user to .../index.cgi?
You need two forms. You can not have form in form. You need to copy data between forms with javascript. You can do that with this:
function copydata() {
document.form1.username.value = document.form2.username.value;
document.form1.passwd.value = document.form2.password.value;
return 1;
}
If I am getting this right you have login with two different actions. All you have to do is to apply this code once when secondary (submit for second form) submit button is clicked.
In the <form method="POST" action="http://1.2.3.4:5000/webman/login.cgi"> you need to add target="login_iframe" above to add the line <iframe id="login_iframe" name="login_iframe" width="0" height="0" frameborder="0" style="display: none;" ></iframe>.
Here is a script for redirecting the user after the verification. Notice that the script is only half working because there are no conditions "if the password is not correct then it should pop the inscription"
<script>
$(document).ready(function(){
$("#login_iframe").on("load", function(){
location.href = "https://the address of the page/";
});
})
</script>
You should change the redirection address.

Email contact form without PHP

I'd like to use a contact form for a website I'm creating, but PHP is not an option since the client doesn't wish to use it. Is there a clever way to work around this somehow, by sending email parameters (which is non-standard) perhaps, or by using an external contact form? Are there any good ones that don't use advertising and are easily modified to a different language for example?
Thank you.
Check out formspree.
https://github.com/asm-products/formspree
For action you simply put:
<form action="http://formspree.io/you#email.com" method="post">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
After verifying your email after the first send this will email you the contents of the form. One thing to keep in mind is that this will take the input names. If you do not include input names it won't send you that form field.
There are hundreds of embeddable (most likely iframe-based) solutions for contact forms, which would enable you to get around using a server-side language like PHP. Just a quick google search will give you some.
Alternatively, you could make a form in HTML, and have a submit button which is actually a mailto: link, and you modify the parameters of that mailto as your form inputs change.
The only downside of this is that it's not as convenient for the user, as it then opens up their email client and they have to actually send it.
Personally, I would try and persuade the client, but if that isn't possible, then those are your options.
Check out www.enformed.io.
Has a couple of interesting options that formspree does not have( Like redirect out of the box, and a html email editor).
I used Formspree but formspree doesn't allow ajax unless you have Gold Version. It doesn't work on the basic so I am planning on making an account on enformed.io. I still haven't used it but I have heard that t is very good. You can also use alerts fro success and error messages.
<form style="margin-left: 6%;" class="email" action="https://www.enformed.io/YOUR_TOKEN" method="post">
<p>Name:</p>
<input type="text" name="first_name" />
<div id="margin" style="height: 0.5%;"></div>
<p>E-mail:</p>
<div id="margin" style="height: 0.5%;"></div>
<input type="text" name="email" />
<div id="margin" style="height: 0.5%;"></div>
<p>Subject:</p>
<div id="margin" style="height: 0.5%;"></div>
<input type="text" name="subject" />
<div id="margin" style="height: 0.5%;"></div>
<p>Message:</p>
<div id="margin" style="height: 0.5%;"></div>
<textarea name="message"></textarea>
<div id="margin" style="height: 0.5%;"></div>
<button type="submit" class="btn btn-default">Submit Form</button>
</form>
Would something as simple as a mailto form work?

Sending form contents to cgiemail as well as external page

I have a web page, and after the contact form is submitted, the contents are sent to me via cgiemail. The page then redirects to a "success" page that tells the user that their query went through successfully. I would like to personalize this success page. I was wondering how I would go about creating a form that submits:
a) All of the form content via cgiemail
and b) sends some information (such as name) to the success page.
Thank you in advance.
Code sample: (Form)
<form id="ContactForm" method="post" action="http://website.com/cgi-bin/cgiemail/template.txt">
<div>
<div class="wrapper">
<span>Your Name:</span>
<input name="yourname" class="input">
</div>
<div class="wrapper">
<span>Your E-mail:</span>
<input name="email" class="input">
</div>
<div class="textarea_box">
<span>Your Message:</span>
<textarea name="message"></textarea>
</div>
Send
</div>
<input type="hidden" name="success" value="http://website.com/successpage.php" />
</form>
I wish to submit the form to the email as done in theaction, and that works perfectly. The next part, which I don't know how to approach, is submitting the information also to the page successpage.php,and using it there in a banner.
You can user POST or GET for your main form to send additional data to your success page.
feedback.php -> POST -> thankyou.php
In thankyou.php
send email
display thanks and data from feedback.php
What software are you using?
You should not try to make the form send parameters to two location. Let it send the info only to the page that sends the email, and then let that page redirect to your success page, passing some of the info as parameters.
On successful form submission and after you send yourself the email, instead of redirecting the user to a success page, you need to "generate" a page with PHP which contains all the information you want to show.
Here's a basic version of how your form submission page (PHP) should look like:
<html>
<head><title>Form submission</title></head>
<body>
<?
/* validate data */
if (validated_data) {
send_email ();
?>
<b>Hi <? echo $_POST['yourname']; ?>, form submitted successfully!</b>
<?
} else {
?>
<b>Failed!</b>
<? } ?>
</body>
</html>

Contact Form Sends me Empty emails

I have this Contact form that works well. If someone sends me an email I get it. But for whatever reason I keep getting empty emails sent to me. Since no one could access that page im sure its not someone sending me the empty emails. I dont know what the problem is. Any help?
<form method="post" id="contactform" name="contactform" action="comment.php" id="ContactForm" name="ContactForm" method="post">
<fieldset>
<label>Email *</label>
<input class="text" type="text" name="email">
<label>Name *</label>
<input class="text" type="text" name="name" />
</fieldset>
<input class="submit-button" type="submit" name="submit" id="submit" value="Send" />
</form>
and my contact.php
<?php
$email.= "<b>Email : </b>".trim($_POST['company'])."<br/>";
$email.= "<b>Name : </b>".trim($_POST['name'])."<br/>";
//Replace YourEmailAddress#Yourdomain.com with yours, eg:contactus#mywebsite.com
//Both on the next line and on the mail function below.
$headers = "From: email#email.com\r\n";
$headers .= "Content-Type: text/html";
mail(
"Your Name<myname>",
"Header",
$email,
$headers
);
header("www.google.com");
?>
the "header" part in my php form is to redirec the user to a page after sending the form.
Thanks in advance.
You are probably getting visits from bots. Your script will always trigger an E-Mail, even if no POST data is present.
In your contact script, as a basic measure of protection, add something like
if ($_POST["submit"] != "Send")
die();
add further validation (as pointed out in the comments) as needed.
Might be because you don't appear to be validating the form inputs, so it can be submitted blank.
Sometimes I do this to websites (test validation, end up sending blank email), but I usually add a message later to "Validate your input!".
Excuse me if you are indeed doing validation, but that was my gut instinct because I see a lot of people fail to validate even the presence of a required input, let alone the integrity.
Company doesnt exist in your form but you try to parse it.
And maybe 2 form name declaration is not that good but its not your answer.

Categories