Ful*_*t98 10 html php forms email
我有三个电子邮件表单,允许用户向我的三封电子邮件之一发送邮件,而无需编写自己的电子邮件.表格正在运行并且正在发送电子邮件,问题是电子邮件发件人和电子邮件信息等信息仅适用于我的"支持"表单,但不适用于其他两种表单("商家","其他") ").我不确定到底出了什么问题.
重要提示,有三种形式的原因,比如我已经完成了,因为我已经制作了三个按钮,称为"业务""支持""其他",然后当您单击其中一个按钮时,将显示特定的表单.
<!-- SUPPORT CONTACT FORM START-->
<div class="contactSupportButton"><input type="image" src="supportContactButtonNew.png" id="contactSupportBut" alt="contact support button" style="height: 40px; width: 100px" onClick="showSupForm()"/>
<div id="contactSupportForm">
<form action="supFormSend.php" method="post" id="contactForms">
<div id="nameLabelForm">
<label for="name">Name:</label><br>
<input type="text" id="nameInput" name="nameInput"/>
</div>
<div id="emailLabelForm">
<label for="mail">E-mail:</label><br>
<input type="email" id="mailInput" name="mailInput"/>
</div>
<div id="messageLabelForm">
<label for="msg">Support Message:</label><br>
<textarea id="messageInput" name="messageInput"></textarea>
</div>
<div class="submitEmailButton">
<button type="submit" id="submitButton">Send message</button>
</div>
</form>
</div>
</div>
<!-- SUPPORT CONTACT FORM ENDING-->
<!-- BUSINESS CONTACT FORM START-->
<div class="contactBusinessButton"><input type="image" src="businessContactButtonNew.png" id="contactBusinessBut" alt="contact business button" style="height: 40px; width: 110px" onClick="showBusForm()"/>
<div id="contactBusinessForm">
<form action="busFormSend.php" method="post" id="contactForms">
<div id="nameLabelForm">
<label for="name">Name:</label><br>
<input type="text" id="nameInput"/>
</div>
<div id="emailLabelForm">
<label for="mail">E-mail:</label><br>
<input type="email" id="mailInput" />
</div>
<div id="messageLabelForm">
<label for="msg">Business Message:</label><br>
<textarea id="messageInput"></textarea>
</div>
<div class="submitEmailButton">
<button type="submit" id="submitButton">Send message</button>
</div>
</form>
</div>
</div>
<!-- BUSINESS CONTACT FORM ENDING-->
<!-- OTHER CONTACT FORM START-->
<div class="contactOtherButton"><input type="image" src="otherContactButtonNew.png" id="contactOtherBut" alt="contact other button" style="height: 40px; width: 110px" onClick="showOtherForm()"/>
<div id="contactOtherForm">
<form action="otherFormSend.php" method="post" id="contactForms">
<div id="nameLabelForm">
<label for="name">Name:</label><br>
<input type="text" id="nameInput"/>
</div>
<div id="emailLabelForm">
<label for="mail">E-mail:</label><br>
<input type="email" id="mailInput" />
</div>
<div id="messageLabelForm">
<label for="msg">Other Message:</label><br>
<textarea id="messageInput"></textarea>
</div>
<div class="submitEmailButton">
<button type="submit" id="submitButton">Send message</button>
</div>
</form>
</div>
</div>
<!-- OTHER CONTACT FORM ENDING-->
Run Code Online (Sandbox Code Playgroud)
<?php
$field_name = $_POST['nameInput'];
$field_email = $_POST['mailInput'];
$field_message = $_POST['messageInput'];
$mail_to = 'support@myemail.com';
$subject = 'Message regarding support from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_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.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to support@myemail.com');
window.location = 'contact.html';
</script>
<?php
}
header('Location: index.html');
exit;
?>
Run Code Online (Sandbox Code Playgroud)
<?php
$field_name = $_POST['nameInput'];
$field_email = $_POST['mailInput'];
$field_message = $_POST['messageInput'];
$mail_to = 'business@myemail.com';
$subject = 'Message regarding business from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_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.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to business@myemail.com');
window.location = 'contact.html';
</script>
<?php
}
header('Location: index.html');
exit;
?>
Run Code Online (Sandbox Code Playgroud)
<?php
$field_name = $_POST['nameInput'];
$field_email = $_POST['mailInput'];
$field_message = $_POST['messageInput'];
$mail_to = 'other@myemail.com';
$subject = 'Message regarding other from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_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.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to other@myemail.com');
window.location = 'contact.html';
</script>
<?php
}
header('Location: index.html');
exit;
?>
Run Code Online (Sandbox Code Playgroud)
乔恩·斯特林给出了您问题的答案。此外,如果表单位于一页上,您应该更改所有不同 html 元素的 id 值。id 在页面上应该是唯一的。它不一定会给你一个错误,但它是错误的,如果你开始使用jquery/javascript,它可能会在将来导致问题。
例如你有 3 次 id="nameInput"