【发布时间】:2017-03-28 15:37:16
【问题描述】:
我已经在这方面工作了一段时间,对 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="jane.doe@example.com">
<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>
非常感谢!
【问题讨论】:
-
您遇到了什么错误?代码是否进入条件?你能成功地使用硬编码值运行单行 mail() 调用吗?
-
在本地服务器上,PHP 邮件功能不起作用,但您可以使用 PhpMailer (github.com/PHPMailer/PHPMailer)。
-
我看不出代码有什么问题。你得到什么错误?也正如@mkaatman 所提到的,你可以在不同的页面上使用普通的 mail() 函数发送电子邮件吗?
-
@MartijnBots
mail function will not work??这是为什么。由于 ISP 的限制,它可能无法发送电子邮件(大多数 ISP 阻止 smtp 25 端口),但它仍然可以在本地发送邮件 -
$subject2似乎未定义?
标签: php html sendmessage