我正在建立一个我在Wamp server 3
下运行的网站,我有一个php联系表单,我希望访问者能够直接从网站发送邮件。
<?php
$myemail = "test.xample@xample.com";
if (isset($_POST['email']))
{
echo "Thank you for contacting us!";
/* Set e-mail recipient */
/* Check all form inputs using check_input function */
$name = ($_POST['name']);
$subject = ($_POST['subject']);
$email = ($_POST['email']);
$message = ($_POST['message']);
$mail = "Hello!
Your contact form has been submitted by:
Name: $name
E-mail: $email
Message:
$Message
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
}
?>
我已经通过运行SMTP Server
和mail()
函数测试了代码,一切正常但我的问题是我的变量$name, $message, $email
没有显示在邮件中
这就是邮件的样子:
$mail = "Hello!
Your contact form has been submitted by:
Name: $name
E-mail: $email
Message:
$Message
End of message
";
但邮件的结果如下:
您好!
您的联系表格已由以下人士提交:
名称:
电子邮件:
消息:
消息结束
所以变量的值是空的......
这是表单的html:
<form class="mt-5 ml-5 mr-5" method="POST" action="handler.php" id="reused_form">
<p id="contactForm" class="h4 text-center mt-5"><strong>Kontakta oss</strong></p>
<!-- input text(Name) -->
<div class="md-form">
<i class="fa fa-user prefix">*</i>
<input type="text" name="name" id="name" class="form-control">
<label for="name">Your name</label>
</div>
<!-- input email -->
<div class="md-form mt-5">
<i class="fa fa-envelope prefix">*</i>
<input type="email" name="email" id="email" class="form-control validate">
<label for="email" data-error="Wrong" data-success="Right">Your email</label>
</div>
<div class="md-form mt-5">
<i class="fa fa-user prefix"></i>
<input type="text" id="subject" class="form-control">
<label for="subject">Subject</label>
</div>
<!-- input message -->
<div class="md-form mt-5">
<i class="fa fa-pencil prefix">*</i>
<textarea type="text" name="message" id="message" maxlength="5000" class="form-control md-textarea" rows="3"></textarea>
<label for="textareaPrefix">Message</label>
</div>
<div class="text-center mt-4 mb-4">
<button class="btn danger-color" type="submit">Submit</button>
</div>
</form>
&#13;
如果有人可以帮我解决这个问题会很高兴......
答案 0 :(得分:1)
在帖子中删除这些大括号(),如下所示
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
并邮寄如下 邮件($ myemail,$ subject,$ mail);
答案 1 :(得分:0)
调试101:
检查变量是否按预期发布。添加var_dump选项
if (isset($_POST['email']))
{
var_dump( $_POST );
如果一切正确,则在处理后检查值:
$name = ($_POST['name']);
$subject = ($_POST['subject']);
$email = ($_POST['email']);
$message = ($_POST['message']);
var_dump( $name, $subject, $email, $message );
如果一切正确,那么请确保通过用大括号括起来处理变量。
$mail = "Hello!
Your contact form has been submitted by:
Name: $name
E-mail: {$email}
Message:
{$Message}
End of message
";
还有其他问题&#39;使用您的代码,因为您在发送数据之前没有检查或清理数据。