i have an html page with text filed , and an action button to open a popup like this example
http://www.andwecode.com/playground-demo/pop-up-login-signup-box-jquery/#modal
(hit login to see the popup) who had also a two text fields , how i can collect the text entered in the 3 boxes (the one in the page and the two in the popup window) simultaneously with a php file ? cause i need to send them all to my email
an exemple of my php file :
<?php
$txt1 = "textfield 1 : ".$_POST['textfield1'];
$txt2= "textfield 2 : ".$_POST['textfield2'];
$tx3= "textfield 3 : ".$_POST['textfield3'];
$message = "
$txt1
$txt2
$txt3
";
$to = "myemail#example.com";
$subject = "data :".$txt1;
$headers = "From: <myemail#example.com>";
$headers = "MIME-Version: 1.0\n";
$from = "example";
mail($to,$subject,$message,$headers,$from);
}
?>
any idea how to collect all the text from the
For PHP to receive the values of three different inputs in a single POST, all three inputs need to be contained within the same HTML <form>. Try moving HTML around so that all inputs are contained in a single form, then they should all be accessible to PHP in the $_POST array.
It seems to me you don't have 'name' attributes on the input tags, try something like this,
<!--ALL THE HTML-->
Email: <input type="text" name="email"></input>
Password: <input type="pass" name="pass"></input>
<!--MORE HTML-->
SEPARATE PHP FILE!!
<?php
function getdata(){
$email= $_GET['email']; //Email
$pass= $_GET['pass']; //Password
$name = $_GET['name']; //Full name (Only will apply if registering)
};//This gets the data and gives it a variable
//Then more php like you had already to email to yourself
?>
In simple terms, add the 'name' attribute to the inputs (name="whatevername") and then use the $_GET in php to get the data ($varname = $_GET['nameattributehere'];).
Just remember!
To put the PHP code in a separate file with the .PHP extension on it (.HTML doesn't work!)
Add the 'name' attributes to the inputs
And on the <form> tag you MUST ADD THIS! method="get" action="srcforthephpfile.php"
Good Luck
Related
My code is same as here: How to send copy of PHP / HTML form to sender's email?
I would want that when I write email address to text box then I will get copy of the form to email I wrote.
I have replaced HTML code:
<label><input type="checkbox" name="sendcopy" value="Yes" checked/>Send copy to your mail</label>
to
<label><b>Write your email here:</b><div style="width: 33%;"><input class="contact-input"style="width: 500px;" name="sendcopy"><br/></div></label>
I have replaced PHP code:
$sendCopy = isset($_POST['sendcopy']);
to
$sendCopy = $_POST["sendcopy"];
And I replaced PHP code:
if ($sendCopy) {
$sentToSender = mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head);}
to
if (mail($sendCopy, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head))
Now when I write email address to text box, I will get the copy of the form to email I wrote, but when I leave the text box to blank the submission of the form ends with an error.
So, the main thing is that when form sender writes his/her email to a text box he/she will get the copy of the form to his/her email. And when you leave the text box blank, the form will send only to recipient email. How can I do this?
I have replaced PHP code:
$sendCopy = isset($_POST['sendcopy']);
That will always be considered as being "set" and will return a Boolean.
And when you leave the text box blank, the form will send only to recipient email. How can I do this?
You're looking to use a ternary operator.
From the manual:
// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
So your attempt would round off to:
$action = (isset($_POST['sendcopy'])) ? 'default' : $_POST['sendcopy'];
While replacing default to what you want it to be as a default.
Side note: isset() in this instance is good for radios buttons and checkboxes. If you don't want empty fields, you could use empty() for text inputs, etc. besides radios buttons and checkboxes.
I'm trying to store data in a .txt file..
The data is already appear on my HTML page but I couldn't know how to post them in a txt file or store them in a session.
In main page:
<?php
echo implode('<br/>', $res->email);
echo json_encode($res->password);
?>'
I want to do something like below:
<?php
$login = "
EMAIL : $_POST['$res->email'];
PASSWORD: $_POST['$res->password']; ";
$path = "login.txt";
$fp = fopen($path, "a");
fwrite($fp,$login);
fclose($fp);
?>
So this $_POST['$res->email']; doesn't work with me I get in the login.txt:
EMAIL : json_encode(Array)
PASSWORD: implode('<br/>', Array)
Neither function calls nor $_POST['$res->email'] would work in string/interpolation context.
While unversed, you should assemble your text data line by line:
$login = " EMAIL : "; # string literal
$login .= implode('<br/>', $res->email); # append function/expression result
$login .= CRLF; # linebreak
$login .= " PASSWORD: "; # string literal
$login .= json_encode($res->password); # append function/expression result
$login .= CRLF; # linebreak
And instead of the oldschool fopen/fwrite, just use file_put_contents with FILE_APPEND flag.
When you use post data you recieve it in your php file. You dont send post data from a php file. With that in mind you manipulate this data with php in the following way:
If is data you recieved from post:
echo $_POST['field'];
This will show the message stored on the field variable among the posted data. But check that the field will be always a string (even though the contents may not be so)
If you want to acces dynamically a field just have in mind that it should be a string for example:
$email = "example#gmail.com";
echo $_POST[$email]
This will NOT return the posted email, but will return the contents from a variable inside Post called "example#gmail.com". Which is the same as :
echo $_POST["example#gmail.com"];
But making now a correct example. if you have this html in your webpage
<form action="/yourphp.php" method="post" target="_blank">
<input type="text" name="email">
<input type="submit" value="Submit">
</form>
you will be able to recover the data from the input field named "email"
echo $_POST['email'];
and this will return the email inside the input.
After you have this clear, you can manipulate the data in different ways to send them to a file, but usually you will have to instantiate a handler, open a file, write content, save and close the file, all depending on your handler.
I have a html form on every page and I need to be able to show in the receiver email from which page the visitor submitted the form. How can I achieve this in PHP? I have tried using $_SERVER['REQUEST_URI'] whatsoever, but it just simply doesn't output anything. I'm using Wordpress.
<?php
global $post;
$post_slug=$post->post_name;
$name = $_POST['firstname'];
$email = $_POST['email'];
$message="$name.$email";
mail('example#gmail.com', "Hello", "$name \n $email \n $_SERVER['REQUEST_URI']");
echo "works";
?>
Your code is fine except, you should enclose array variables inside strings with curled braces {}:
mail('example#gmail.com', "Hello", "$name \n $email \n {$_SERVER['REQUEST_URI']}");
If you check the official php documentation on: http://php.net/manual/en/language.types.string.php#language.types.string.parsing you can see in section "Complex (curly) syntax":
// Works, quoted keys only work using the curly brace syntax
echo "This works: {$arr['key']}";
you can get the actual url with :
$actual_link = "http(s)://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
You can try something this . Pass the title of your page ( or the permalink ) to a hidden html input and take the values as :
$titlePage = get_the_title($post->ID);
<input type="hidden" value="<?php echo $titlePage; ?>" name="pagetitle">
Then in your email code :
$pagetitle = $_POST['pagetitle'];
Now you have your parameter, use it in your email like you want.
i'm using ajax contact form, downloaded from: http://youhack.me/2010/07/22/create-a-fancy-contact-form-with-css-3-and-jquery/
Everything works ok except UTF as i can't use cyrilic symbols when submitting.
The php:
$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender
$web = $_POST['web']; // Your website URL
$body = $_POST['text']; // Your message
$receiver = "receiver#domain.com" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to
if (!empty($name) & !empty($email) && !empty($body)) {
$body = "Name: {$name}\n\nSubject: {$web}\n\nMessage: {$body}";
$send = mail($receiver, 'Contact from domain.com', $body, "From: {$email}");
if ($send) {
echo 'true'; //if everything is ok,always return true , else ajax submission won't work
}
}
It uses jquery.validationEngine-en for validation.
My html already has "Content-Type" content="text/html; charset=utf-8" in header.
I'm new to php and jquery, so i would appriciate some guidance to make UTF-8 work when submitting.
Thanks :)
Edit: When i try to use cyrilic chars (čšćđ) on a required field i get ajax input error "Please use letters only". If i submit the form with cyrilic chars on a non-required field, i receive and email, all letters show ok except cyrilic, which are like this: Å¡.
Edit 2: When i set the recipient to gmail (webmail), cyrilic chars show up ok, except in one field, where Ajax doesnt let me use them (regex from Reinder answer).
When i set recipient in outlook (local) and submit the form, none of the cyrilic chars don't show up ok, example: ÄĹĄ oÄa ĹĄ ÄŽŠÄÄ
SOLVED Thanks to Reinder for guide and David! Will solve it today :)
having looked at the plugin you're using, I think this has to do with the validation regex inside jquery.validationEngine-en.js
when the validation is set to 'onlyLetter' it will check using
/^[a-zA-Z\ \']+$/
and none of your characters čšćđ are allowed here...
you need to create a language validation javascript for the language you're using and change that regular expression. For example, have a look at this post
The next thing is to check the encoding of your PHP file and your headers.
Place this at the top of your PHP code
header("Content-type: text/html; charset=utf-8");
Check if the values are correctly displayed when just outputting them in PHP, like so:
echo $name;
If they are correctly displayed in the browser and it's just the email that's incorrectly displaying the characters, then you need to pass an encoding header to the email too
example:
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$body = "Name: {$name}\n\nSubject: {$web}\n\nMessage: {$body}";
$send = mail($receiver, 'Contact from domain.com', $body, $headers);
have a look at the mail function on the PHP.NET website
Rather than use the default PHP mail() function, I've found this come in handy when working with Japanese:
http://bitprison.net/php_mail_utf-8_subject_and_message
I have a page with multiple forms (2 forms) on that page.
There is a callup form and a contacts form in the footer of the page.
So customers may choose to just enter a phone nr and press submit in one form, or they may fill in the other form with name, email, and a message and then press submit.
I am working on a PHP mail() function to separate which form is beeing submitted, however I have forgot alot of programming over the last time, so I turn to you again in asking what to do here.
How can I in the PHP code separate which form has been submitted?
This is what I have in the php right now:
$type = $_POST['type'];
if($type == 'callup'){
$tel_nr = $_POST['tel'];
$to = 'info#domain.se';
$subject = 'Call customer';
$message = 'Client telephone nr is '.$tel_nr.'.';
$message .= '\n';
$message .= 'Client signed in at this date and time: '.date('Y-m-d').' Time: '.date('H:m:s').'';
mail($to, $subject, $message);
}
Basically what I want to do is to send an email to myself when customer submits a form. But depending on which form customer submits, I want to send the corresponding email.
Use multiple names for submitting:
In your first form:
<input type="submit" name="address" value="Submit Address" />
In your second form:
<input type="submit" name="zipcode" value="Submit Zipcode" />
Then, serverside, check for the available names:
if (isset($_POST['address'])) {
// ...
} else if (isset($_POST['zipcode'])) {
// ...
}
Send each form to a different action:
<form action="foo.php" method="post">
<!-- phone number form -->
</form>
<form action="bar.php" method="post">
<!-- name/email/message form -->
</form>
Then each PHP script would do what it needs to do for the given inputs, and redirect back to your forms page at the end. Advantage: each script only needs to worry about its own set of inputs, and you avoid big ifs and/or switches that toggle on an "action" flag.
If you have only one form you can use a better name to identify each form. For example you can add a prefix form1_ to each input object and form2 to each second form input object. Then you can add a default value to each input object to identify the object.
Or you can add hidden field and check if that field is set and process one kind of form.
The simples way will be checking if that key exists as part of array using array_key_exist
if(array_key_exist("form1")){}
else if(array_key_exist("form2")){}