PHP-通过邮件发送两个字段
我有一个带有两个文本框和一个提交按钮的文档。我想在按下提交按钮时发送一封电子邮件,其中应该有文本框的值。我的PHP知识有点陈旧。我不想用emailproces来打扰用户,所以他看不到这一点,应该被重定向PHP-通过邮件发送两个字段,php,Php,我有一个带有两个文本框和一个提交按钮的文档。我想在按下提交按钮时发送一封电子邮件,其中应该有文本框的值。我的PHP知识有点陈旧。我不想用emailproces来打扰用户,所以他看不到这一点,应该被重定向 <html> <body> <div class="section_form" id="usernameSection"> <label for="username">Login:</label> <input size="
<html>
<body>
<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" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Submit</button>
</div>
</body>
</html>
登录:
电邮:
提交
非常感谢 使用PHP邮件函数-列出
这应该会有所帮助。使用PHP邮件函数-列出
这应该会有所帮助。基本上,你要寻找的核心是
<?php
// Check that all fields are present, construct the message body, etc
mail($to, $subject, $body);
header("Location: wherever.php");
exit();
?>
请参阅PHP文档中的。(同时,感谢Alex的退出提醒。)基本上,你要寻找的核心是
<?php
// Check that all fields are present, construct the message body, etc
mail($to, $subject, $body);
header("Location: wherever.php");
exit();
?>
请参阅PHP文档中的。(另外,感谢Alex的退出提醒。)从以下内容开始:-
- 您还需要选中:,您可能希望使用
表单将输入字段的数据发送到服务器。从:
-
-
您还需要选中:,您可能希望使用表单
将输入字段的数据发送到服务器。将此代码用于您的任务
<?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>
登录:
电邮:
提交
将此代码用于您的任务
<?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>
登录:
电邮:
提交
发送位置
标题后,别忘了退出位置。位置会重定向我,对吗?您如何将用户名和电子邮件绑定到$message?请参阅ssapkota的答案-基本上使用$\u POST['username']
和$\u POST['email']
进行验证。发送位置
标题后,不要忘记退出。位置重定向我,对吗?您如何将用户名和电子邮件绑定到$message?请参阅ssapkota的答案-基本上在验证后使用$\u POST['username']
和$\u POST['email']
。