我正在尝试将index.php中的电子邮件地址发送到form.php文件。在form.php中,我正确地获取了电子邮件地址或正确打印。但是当我尝试使用php mail()函数向该特定电子邮件地址发送电子邮件时。它不起作用。任何人都可以建议我如何解决这个问题?
的index.php
<form method="POST" action="Form.php">
<input type="email" name="email" placeholder="Email" >
<input type="submit" name="submit" id="submit-form" class="hidden" style="display:none">
</form>
form.php的
<p>To :'.$_POST["email"].'</p> // showing email address
<?php
if (isset($_POST['submit'])) {
$to = $_POST["email"]; // does not sending email
$subject = 'my subject';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: my@email.com';
mail($to, $subject, $hippo , implode("\r\n", $headers));
}
?>
<div id="submitBtn">
<label for="submit-form" class="submitBtn">Submit</label>
</div>
答案 0 :(得分:1)
您的表单中没有提交按钮,并且您询问提交是否在表单中 正确的方法是
<form method="POST" action="Form.php">
<input type="email" name="email" placeholder="Email" >
<input type="submit" value="submit"/>
</form>
现在 Form.php 的代码将起作用
答案 1 :(得分:0)
检查标题和mail()
功能,看看它是否实际上将您重定向到表单页面,
尝试下面的代码:
<强>索引强>
<form method="POST" action="Form.php">
<input type="email" name="email" placeholder="Email">
<input type="submit" name="submit" id="submit-form">
</form>
<强>表格强>
$to = $_POST['email'];
$subject = "My Subject" ;
$message = "Got the mail";
$header = "From: my@email.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
mail($to, $subject, $message, $header);