向填写表格的用户发送确认电子邮件

时间:2013-02-07 08:50:54

标签: php html email

这是我的HTML表单

 <form method="post" name="myemailform" action="form-to-email.php">
<p>
    <label for='name'>Enter Name: </label><br>
    <input type="text" name="name">
</p>
<p>
    <label for='email'>Enter Email Address:</label><br>
    <input type="text" name="email">
</p>
<p>
    <label for='message'>Enter Message:</label> <br>
    <textarea name="message"></textarea>
</p>
<input type="submit" name='submit' value="submit">
 </form>

这是PHP邮件代码,当用户点击提交时抓取数据

<?php
if(!isset($_POST['submit']))
{

echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

//Validate first
if(empty($name)||empty($visitor_email)) 
{
echo "Name and email are mandatory!";
exit;
}
$email_from = 'tom@amazing-designs.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
 "Here is the message:\n $message".

$to = "khan.koder@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";

mail($to,$email_subject,$email_body,$headers);

//done. redirect to thank-you page.

header('Location: thank-you.html');

?> 

它显示没有错误,但只是登陆页面thank-you.html我检查了我的电子邮件帐户,但没有收到邮件

请帮忙什么不对

1 个答案:

答案 0 :(得分:0)

您可以按照以下方式实现:

1)在数据库中创建一个激活的字段(默认为 false ) 2)注册后,电子邮件将被发送 3)填写电子邮件中的链接,包括...

a) user unique identifier 
b) activation to active

因此看起来可能是这样的 [码] 欢迎用户名_ 。感谢您注册,请点击以下链接激活您的帐户 domain.com/register.php?uid=100&activate=1

4)您的注册脚本试图通过id抓取用户 5)将激活的字段更新为 true

你有一个新的活跃用户。

愿它能给你一个想法。