开发者

PHP - send two fields through mail

I have a document with 2 textboxes and 1 submit button. I want to send an email when I press the submit button and in it should be the value of the textboxes. My PHP knowledge is a bit dusty. I don't want to bother the user with the emailproces, so he can't see this and should just be redirected.

<html>
<body>

<div class="section_form" id="usernameSection"> 
<label for="username">Login:</lab开发者_运维问答el> 
<input size="20" type="text" name="username" id="username" /> 
</div> 

<div class="section_form" id="emailSection"> 
<label for="email">Email:</label> 
<input size="20" type="text" id="email" name="email" maxlength="20"/> 
</div> 

<div id="submit_button"> 
<button type="submit" value="Submit" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Submit</button> 
</div>

</body>
</html>

Many thanks!


Use the PHP mail function - listed here.

That should be able to help.


Basically the core of what you're looking for is

<?php
// Check that all fields are present, construct the message body, etc
mail($to, $subject, $body);
header("Location: wherever.php");
exit();
?>

See the mail function in PHP documentation. (Also, thank you Alex for the exit() reminder.)


Use this code for your task.

<?php 
if(isset($_POST['submit'])){
    extract($_POST);
    $message = "username : $username ; email : $email";
    $to = "your@email.com";
    $subject  = "Email Subject";
    mail($to, $subject, $message);
    }
    ?>

<html>
<body>
<form method="POST" name="form1">
<div class="section_form" id="usernameSection"> 
<label for="username">Login:</label> 
<input size="20" type="text" name="username" id="username" /> 
</div> 

<div class="section_form" id="emailSection"> 
<label for="email">Email:</label> 
<input size="20" type="text" id="email" name="email" maxlength="20"/> 
</div> 

<div id="submit_button"> 
<button type="submit" value="Submit" name="submit" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Submit</button> 
</div>
</form>
</body>
</html>


Start with:
- $_POST
- mail()

Also you need to check: Forms in HTML, you might want to use form to send the data of input fields to server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜