我一直在研究這個問題一段時間,而且對於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,你可以用簡單的郵件()函數在不同的頁面上發送電子郵件嗎? –