This question already has answers here:
Html form in email
(3 answers)
Closed 7 years ago.
I create many newsletters. Is it possible to add a php form in email ? I explain, the customer open this email and on this email he see an input to add his email. Is it possible for me to keep the data ? For example we can imagine a simple input to subscribe newsletter.
ya its possible... you need have a form in your email template and in form action you need to specify the php file which is there in your domain
E.x:
in your email template
<form method="GET" action="http://www.yourdomain.com/back_end_file.php">
<label>Email id</label>
<input type="text" name="email" />
<input type="submit" value="submit" />
</form>
In your server file i.e : http://www.yourdomain.com/back_end_file.php
<?php
echo $email = $_GET['email'];
?>
If it gives some cross domain issue then paste below code in first line in http://www.yourdomain.com/back_end_file.php this file
<?php header('Access-Control-Allow-Origin: *'); ?>
I hope this works...
Related
This question already has answers here:
Chrome: ERR_BLOCKED_BY_XSS_AUDITOR details
(8 answers)
Closed 4 years ago.
I have one page where I submit hidden form where I store a large html code that is made in javascript and I want to send that code via form to another php file. It should work but my browser blocks it(google chrome):
<form action="napravi.php" method="post">
<input type="text" name="code" value=""/>
<input type="submit" id="forma_napravi"/>
</form>
and in javascript:
document.getElementById("forma_napravi").click();
and php page where I send the form data:
if(isset($_POST['code'])){
echo $_POST['code'];
}
and this is error that browser shows to me:
It will show error if you send html or javascript code this way because it is google chrome's in-built design.
I tried your code it was working. But when I put some code in place of blank, e.g. value="<script>alert('123');</script>", I got the same error
You may use htmlentities() to parse the html to string. Then the code you send will have no effect at all.
give your form an id and check if it is been submitted. like this-
In your html file
<form action="napravi.php" method="post" id="form">
<input type="text" name="code" value=""/>
<input type="submit" id="forma_napravi"/>
</form>
In your javascript
document.getElementById("form").on('submit', function(){
// your code
});
Hope this will help
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I want the form to send the contents to my email, instead it's just displaying my php code in a new window, can anyone help? here is the code:
Index
<form action="send.php" method="POST">
Name: <br><input type="text" name="name"><br><p>
Request: <br><textarea name="request"></textarea><p>
<input type="submit" name="submit" value="Send!">
</form>
PHP:
<?php
$name = $_POST['name'];
$request = $_POST['request'];
$to = "myemail#email.co.uk";
$subject = "It's just a test";
$body = "This is just a test to see if things are working okay \n\n $request";
mail ($to,$subject,$body);
echo "Message sent!"
?>
Few tips for beginners
First Configure your Xampp form send email How to configure XAMPP to send mail from localhost?
Check if the data is coming to send.php by print_r($_POST)
Follow this tutorial for sending email from here
This question already has answers here:
How do I make a redirect in PHP?
(34 answers)
PHP fopen for writing fails
(2 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
So i have a contact form on my website. However when i submit it redirects me from my html page to the PHP page, id like to automatically redirect back. I have tried using HTACCESS but it redirects straight away and the PHP script doesnt run.
HTML FORM
<form action="action.php" method="post" class="contactForm" target="_top">
<input type="name" name="field1" placeholder="Enter your name..."><br>
<input type="email" name="field2" placeholder="Enter your email address..."><br>
<input type="text" name="field3" placeholder="Enter your message..."><br>
<input type="submit" value="Submit" id="button">
</form>
action.php
<?php
$path = 'data.txt';
if (isset($_POST['field1']) && isset($_POST['field2'])&& isset($_POST['field3'])) {
$fh = fopen($path,"a+");
$string = $_POST['field1'].' - '.$_POST['field2'].' - '.$_POST['field3'];
fwrite($fh,$string);
fclose($fh);
}?>
If i am going about this the wrong way please let me know, i am a complete beginner to PHP so i know very little.
Thanks.
header('Location: index.html');
http://php.net/manual/en/function.header.php
You can't output anything before the redirect.
A potentially better way to do this is not to post to the PHP script only to have it redirect back to html, but to post to it through ajax.
There are a few ways to do that. I assume you want to take the values from the Form and process them in PHP.
Using Ajax - With Ajax you can send data from your form to a PHP-Script without reloading the page. So in your case no redirect is needed See here for a small tutorial http://blog.teamtreehouse.com/create-ajax-contact-form
Combine PHP and HTML - You can input all your HTML Code into the PHP File and call the PHP File. See -> https://www.ntchosting.com/encyclopedia/scripting-and-programming/php/php-in/
ob_end_clean( );
header("Location: example.com");
exit();
Allows you to output something before redirecting.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm new to PHP, but I found some sample code for a web form. I adapted it like this, in a file called contact.php:
<?php
mail('contact#mywebsite.com', $_POST['name'], $_POST['email'], $_POST['subject'], $_POST['message']);
?>
<p>Your message has been sent.</p>
and here's the HTML:
<form action="contact.php" method="post" enctype="text/plain">
Name<br>
<input type="text" name="name" value=""><br><br>
Email<br>
<input type="text" name="email" value=""><br><br>
Subject<br>
<input type="text" name="subject" value=""><br><br>
Message<br>
<textarea name="message" rows="10" cols="50"></textarea><br><br>
<input type="submit" value="SUBMIT">
</form>
It wasn't working, so I did some research and discovered Bluehost requires you to use their own Bluemail for this. So I ditched the PHP and followed their tutorial. That didn't work either, so I did some more research and discovered they discontinued Bluemail. So I went back to the PHP method and changed the email to a bluehost email address (apparently that's required as well).
Long story short, I checked my junk mail folder and found some of the test emails I had tried to send from the form, but they are all blank. No subject, no message content.
So it seems like the contact form is working (in that it sends an email), but the actual information inputted in the form is not coming through. I assume there's a problem with my PHP code?
Any help would be greatly appreciated!
Seems you are using wrong syntax for mail
Try
<?php
$msg = $_POST['name']."<br/>". $_POST['email']."<br/>". $_POST['message'];
mail("contact#mywebsite.com",$_POST['subject'],$msg);
?>
You can try this code (perhaps will work for you):
<?php
$msg = $_POST['name']."<br/>". $_POST['email']."<br/>". $_POST['message'];
if (isset($_POST["email"])) {
mail($_POST["email"],$_POST['subject'],$msg);
echo "Your message has been sent.";
}else{
echo "N0, mail is not set";
}
?>
This question already has answers here:
Post and get at the same time in php
(6 answers)
Closed 9 years ago.
Regards.
I want to send some of my values in the form by GET method and some by POST method. How can i do it ?
Here is an example. I wan to make this kind of page, but i want a single submit button for both the forms. Is it possible to use GET method on some feilds and POST method on some ?
<html>
<form name="f2" action="a.php" method="POST">
Name: <input type="text" name ="uname"/><br>
Password: <input type="password" name ="pass"/><br>
<input type="submit" >
</form>
<br><br>
<form name="f1" action="a.php" method="GET">
Fav Movie: <input type="text" name="favmovie"><br>
Movie rating:<input type="text" name="rating"><br>
<input type="submit" value="My FAv movie">
</form>
</html>
HttpRequests do not allow for multiple request types, however you could do
<form method="post" action="answer.php?foo=bar">
You cannot send the values of some input fields via GET and others via POST with PHP and HTML.
If you add JavaScript, you could add the values of some input fields to the query string of the action-attribute of the form. But this seems to be too much of a hassle.
For same submit button -
It will be only possible if you start your form tag with conditional Programming.
i.e. after rendering from web server it will show only one form tag for a specific submit button.
Hope this helps you.
The first question is, why would you want to do that?
I think the simple answer is no, a form can only be submit via one method, by get or post