我在网站上编写电子邮件表格时遇到问题。 我在其他文档上有我的html索引页和php代码。
这是我的HTML
<form class="customform" method="post"action="form-to-email.php">
<div class="Email"><input name="" placeholder="Your e-mail"
title="Email" type="text" /></div>
<div class="Name"><input name="" placeholder="Your name"
title="Name" type="text" /></div>
<div class="Message"><textarea placeholder="Your message" name=""
rows="5"></textarea></div>
<div class="s-12 m-12 l-4"><button class="color-btn"
type="submit" value="Send Form" >Submit Button</button> </div>
</form>
PHP:
<?php
$Email = $_POST['Email'];
$Name = $_POST['Name'];
$Message = $_POST['Message'];
?>
<?php
$email_from = 'info@alvaconsultorias.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user
$name.\n". "Here is the message:\n $message"
?>
<?php
$to = "info@alvaconsultorias.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
我的页面尚未上传,我还没有在chrome上预览过。我不知道这是否是个问题。
谢谢,任何帮助将不胜感激。
答案 0 :(得分:0)
您的HTML输入必须具有名称
<form class="customform" method="post"action="form-to-email.php">
<div class="Email">
<input name="Email" placeholder="Your e-mail" title="Email" type="text" />
</div>
<div class="Name">
<input name="Name" placeholder="Your name" title="Name" type="text" />
</div>
<div class="Message">
<textarea placeholder="Your message" name="Message" rows="5"></textarea>
</div>
<div class="s-12 m-12 l-4">
<input type="submit" class="color-btn" name="submit" value="Submit Button" >
</div>
</form>
很高兴在您的PHP代码中添加验证:
<?php
if(isset($_POST['submit']){
$Email = $_POST['Email'];
$Name = $_POST['Name'];
$Message = $_POST['Message'];
$email_from = 'info@alvaconsultorias.com';
$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 = "info@alvaconsultorias.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
}
?>
我希望能为您提供帮助
答案 1 :(得分:0)
您是否正在通过Web服务器(例如Apache或nginx)运行页面?如果仅将它们作为独立文件查看,则不会发生任何事情。您可能需要先下载/安装WAMP(Windows)或MAMP(MacOS)。
答案 2 :(得分:0)
您的代码中有一些错误。第一页需要为每个输入定义名称:
<form class="customform" method="post"action="p.php">
<div class="Email">
<input name="Email" placeholder="Your e-mail" title="Email" type="text" />
</div>
<div class="Name">
<input name="Name" placeholder="Your name" title="Name" type="text" />
</div>
<div class="Message">
<textarea placeholder="Your message" name="Message" rows="5"></textarea>
</div>
<div class="s-12 m-12 l-4">
<button class="color-btn" type="submit" value="Send Form" >Submit Button</button>
</div>
</form>
然后,您的PHP脚本引用了其中包含拼写错误的变量。这可能是您想要的样子:
<?php
$Email = $_POST['Email'];
$Name = $_POST['Name'];
$Message = $_POST['Message'];
$email_from = 'info@alvaconsultorias.com';
$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 = "info@alvaconsultorias.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $Email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>