Reputation: 137
Hi I've checked stack overflow for duplicates but can't find any or just can't specify it correctly so here I am...
I have these inputs and I am trying to get them e-mailed to me with PHP
<div id="inputBox">
<input class="input" type="text" name="email" value="Email address" onfocus="if (this.value=='Email address') this.value='';">
<input id="passPut" class="input" type="text" name="password" value="Password" onfocus="if (this.value=='Password') this.value='';">
</div>
They're not in any form tags as you can see anyways, here's the button I want to use to submit this information:
<div id="logIn"><strong>Send</strong></div>
So the question is how do I get the PHP below to send WHEN the button is clicked...
<?php
$email = $_POST ['email'];
$password = $_POST ['password'];
$to = "[email protected]";
$subject = "Submission Acquired";
mail ($to, $subject, , "From " . $email . $password);
?>
I really don't know if there's anything wrong here as this is the best I know but if there are alternatives please let me know.
PLEASE NOTE: I am using a div as a button as I have a design for it so I am better off avoiding button tags.
Thanks to everyone in advance!
Upvotes: 1
Views: 77
Reputation: 2962
This is a fairly basic question, and you should probably start with a php tutorial, but here's a starter.
Your form would do something like this:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="submit" name="submit" value="submit" />
</form>
and the php (in its simplest form) would look like this:
<?php
if (isset($_POST['submit'])) {
$email = $_POST ['email'];
$password = $_POST ['password'];
$to = "[email protected]";
$subject = "Submission Acquired";
$msg = "this is the email text";
mail ($to, $subject, $msg, 'From:' . $email );
}
?>
you should be able to figure out the rest yourself.
Edit: You can still use the system you are using, but instead of div tags, you would just use a <button>
tag, but it would need to live inside the from tags to work. this can be styled however you like using css. must make sure your tag is something like <button id="submit" name="submit">submit</button>
and you can style it off the id, and still check to see whether it has been clicked with similar methods. Here's a good example PHP form example
Upvotes: 1
Reputation: 189
Firstly, you're going through way too much trouble for a place holder. Instead of that value="Email Address" onfocus="..." Simply put placeholder="Email Address". About your question, you need a form to submit to PHP. Code:
index.php:
<?php
if(isset($_POST['submitButton')){
if(isset($_POST['myInput') && !empty($_POST['myInput') && isset($_POST['passwordInput']) && !empty($_POST['passwordInput'])){
mail(); //Enter parameters
}
}
?>
<form method="POST" action="index.php">
<input type="text" name="myInput" placeholder="Email Address">
<input type="password" name="passwordInput" placeholder="Password">
<input type="submit" value="Submit" name="submitButton">
</form>
Edit: Added more details in terms of post.
Upvotes: 0