我一直在研究这个问题一段时间,而且对于PHP来说还是比较新的。我无法将其发送。这个代码的第二双眼睛将是最有帮助的:HTML/PHP从表单发送电子邮件
<?php
if(isset($_POST['submit'])){
$to = "myEmail"; // this is your Email address
$from = $_POST['emailAddress']; // this is the sender's Email address
$fullName = $_POST['fullName'];
$subject = "Form submission";
$message = $fullName . " wrote the following:" . "\n\n" . $_POST['comment'];
$message2 = "Here is a copy of your message " . $fullName . "\n\n" . $_POST['comment'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $fullName . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<form method="post" action="contact.php">
<div class="form-group">
<label for="fullName">Name</label>
<input type="text" class="form-control" id="fullName" name="fullName" placeholder="Jane Doe">
<label for="emailAddress">Email</label>
<input type="email" class="form-control" id="emailAddress" name="emailAddress" placeholder="[email protected]">
<label for="comment">Comment</label>
<textarea class="form-control" rows="3" name="comment" placeholder="Comment"></textarea>
<button name="submit" type="submit" class="btn">Submit</button>
</div>
</form>
非常感谢!
你得到了什么错误?代码是否进入条件?你可以用硬编码的值成功地运行单线邮件()调用吗? – mkaatman
在本地服务器上,PHP邮件功能不起作用,但您可以使用PhpMailer(https://github.com/PHPMailer/PHPMailer)。 –
我在代码中看不到任何错误。你得到什么错误?也作为@mkaatman moentioned,你可以用简单的邮件()函数在不同的页面上发送电子邮件吗? –