所以我一直在使用聯繫表格,我創建了一些php和html表格,但是它把所有東西都發送到我的電子郵件中,除了用戶放在表單中的電子郵件。下面,沒有什麼工作還沒有聯繫表格(Php和html
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail_to = '[email protected]';
$subject = 'Message from a site visitor '.$name;
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$message;
$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to [email protected]');
window.location = 'contact_page.html';
</script>
<?php
}
?>
HTML:
<form action="contact.php" method="post">
<div class="row">
<div class="col-md-4">
<input type="text" class="form-control" id="name" placeholder="Name">
<input type="text" class="form-control" id="email" placeholder="Email">
<input type="text" class="form-control" id="subject" placeholder="Subject">
</div>
<div class="col-md-8">
<textarea class="form-control" id="message" rows="25" cols="10" placeholder=" Message Texts..."></textarea>
<button type="button" class="btn btn-default submit-btn form_submit">SEND MESSAGE</button>
</div>
</div>
</form>
你提供的代碼似乎沒有錯誤,但是你可以通過添加echo $ email來檢查是否正在接收值。 – Manikiran
對不起聽起來像一個noob,但我是。我在哪裏添加 – sabregames
您需要在輸入字段中添加'name'-tags。沒有他們,他們將不會被張貼。例如:'