在HTML和PHP中创建邮件表单的步骤如下:
示例代码如下:
<form action="send_email.php" method="post">
<label for="recipient">收件人邮箱地址:</label>
<input type="email" id="recipient" name="recipient" required><br><br>
<label for="subject">主题:</label>
<input type="text" id="subject" name="subject" required><br><br>
<label for="content">内容:</label><br>
<textarea id="content" name="content" rows="5" cols="50" required></textarea><br><br>
<input type="submit" value="发送邮件">
</form>
示例代码如下:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$recipient = $_POST["recipient"];
$subject = $_POST["subject"];
$content = $_POST["content"];
// 发送邮件
$result = mail($recipient, $subject, $content);
if ($result) {
echo "邮件发送成功!";
} else {
echo "邮件发送失败!";
}
}
?>
这样,当用户填写并提交表单时,PHP脚本将获取表单字段的值,并使用mail()函数发送邮件给指定的收件人。
推荐的腾讯云相关产品:腾讯云邮件推送(https://cloud.tencent.com/product/ses)
领取专属 10元无门槛券
手把手带您无忧上云