我有一个表单,用户输入消息,消息被发送到另一端的收件人。我已经多次尝试这个脚本,浏览了教程,但我似乎无法找到问题所在。有任何想法吗?
HTML 表单:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<?php
if(isset($sent))
echo 'Your message has been sent. '; ?>
<label for="Name">Name</label><br />
<input type="text" class="textbox" size="35" id="Name" name="Name" <?php if(isset($name)) echo "value=\"$name\"";?> /><br />
<label for="Service">Service</label><br />
<input type="text" size="35" class="textbox" id="Service" name="Service" <?php if(isset($subject)) echo"value=\"$subject\"";?> /><br />
<label for="Email">Email</label><br />
<input type="text" size="35" class="textbox" id="Email" name="Email" <?php if(isset($from)) echo"value=\"$from\""; ?> /><br />
<label for="message">Message</label><br />
<textarea rows="95" cols="100" id="message" name="message"><?php if(isset($message)) echo"$message"; ?></textarea><br />
<button type="submit">Send Message</button>
</form>
PHP:
if(isset($_POST['Name']) && isset($_POST['Email']) && isset($_POST['Service']) && isset($_POST['message'])) {
$name = $_POST['Name'];
$from = $_POST['Email'];
$subject = $_POST['Service'];
$to = "emailtestertora@gmail.com";
$message = $_POST['message'];
mysql_query("INSERT INTO `Contact`(`Name`, `Email`, `Message`, `Service`) VALUES('$name', '$from', '$message', '$subject')");
$headers = "From:".$from;
if(mail($to,$subject,$message,$headers))
$msgsent = true;
}
谢谢!