每當我訪問我的網站或刷新它時,我的表單都會向我發送一封空白電子郵件(字段數據爲空)。發送電子郵件登陸/刷新網站時的表格
我看了一些提到'Post/Redirect/Get'的帖子,但是這讓我困惑不止,而且我不確定它是否與我的確切問題有關。
這是一個我在網上找到的基本響應表單,必須找到PHP來實際發送表單數據。 (改變它以適應我的需求)
我希望只有一個錯誤,我錯過了某處,但我似乎無法找到它。
任何幫助將不勝感激。提前致謝。
下面是基本形式(不含CSS):
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
HTML:
<form id="contact-form" action="/" method="post">
<h3>Say Hello!</h3>
<h4>Fill in the form below, and I'll get back to you as soon as i can. Thanks!</h4>
<div>
<label>
<span>Name: (required)</span>
<input placeholder="Please enter your name" type="text" name="name" tabindex="1" required autofocus>
</label>
</div>
<div>
<label>
<span>Email: (required)</span>
<input placeholder="Please enter your email address" type="text" name="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telephone: (required)</span>
<input placeholder="Please enter your number" type="text" name="phone" tabindex="3" required>
</label>
</div>
<div>
<label>
<span>Message: (required)</span>
<textarea placeholder="Include all the details you can" type="text" name="message" tabindex="5" required></textarea>
</label>
</div>
<div>
<button name="submit" type="submit" id="contact-submit">Send Email</button>
</div>
</form>
非常感謝:你在'if(isset($ _ POST ['submit'])''末尾缺少一個額外的')'',但它工作得很好。感謝你的幫助。乾杯。 – Aquious