把表单内容发送到邮箱

读者回函
姓  名:
电子邮件:
内  容:

 

-----------------------------------------------------------------

<style>
input {background-color:'99ffff';color:"red"}
textarea {background-color:'99ffff';color:"red"}
</style>
<body bgcolor="99ffff">
<form method="post" enctype="text/plain" action="mailto:yzhang0207@126.com?subject=hello">
<table>
<caption>读者回函</caption>
<tr><td>姓  名:<td><input type="text" name="username">
<tr><td>电子邮件:<td><input type="text" name="email">
<tr><td valign="top">内  容:<td><textarea name="msg" rows="2" cols="30">你好!!!</textarea>
<tr><td colspan="2" align="center"><input type="submit" value="填好了">
</table>
</form>
</body>

-----------------------------------

如果想直接在这篇文章中的控件中做试验,提交表单时会与文章下面的评论有冲突!!

以下是一个简单的HTML表单,可以通过PHP将表单数据发送到指定的邮箱: ```html <!DOCTYPE html> <html> <head> <title>Contact Form</title> </head> <body> <h2>Contact Us</h2> <form action="send_email.php" method="POST"> <label for="name">Name:</label> <input type="text" id="name" name="name" required><br><br> <label for="email">Email:</label> <input type="email" id="email" name="email" required><br><br> <label for="message">Message:</label> <textarea id="message" name="message" required></textarea><br><br> <input type="submit" value="Send"> </form> </body> </html> ``` 在上面的表单中,我们使用了POST方法将表单数据发送到一个名为send_email.php的文件中。下面是send_email.php文件的示例代码,其中使用了PHPMailer库来发送邮件: ```php <?php // 引入PHPMailer库 require 'PHPMailer/PHPMailerAutoload.php'; // 获取表单数据 $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; // 实例化PHPMailer $mail = new PHPMailer; // 设置SMTP服务器信息 $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; // SMTP服务器地址 $mail->SMTPAuth = true; $mail->Username = 'your_email@gmail.com'; // SMTP登录账号 $mail->Password = 'your_email_password'; // SMTP登录密码 $mail->SMTPSecure = 'tls'; $mail->Port = 587; // 设置件人信息 $mail->setFrom($email, $name); // 设置收件人信息 $mail->addAddress('recipient_email@example.com', 'Recipient Name'); // 设置邮件主题和内容 $mail->Subject = 'New Contact Message'; $mail->Body = $message; // 发送邮件 if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?> ``` 在send_email.php文件中,我们首先获取了通过表单提交的数据,然后使用PHPMailer库实例化一个邮件对象。接下来,我们设置了SMTP服务器信息、件人信息、收件人信息、邮件主题和内容。最后,我们调用$mail->send()方法发送邮件。 请注意,以上示例代码仅供参考,在实际使用中需要根据具体情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值