【发布时间】:2015-07-12 06:58:23
【问题描述】:
我有三个电子邮件表单,它允许用户向我的三个电子邮件之一发送消息,而无需编写自己的电子邮件。表格正在工作并且正在发送电子邮件,问题是电子邮件发件人和电子邮件消息等信息仅适用于我的“支持”表格,但不适用于其他两种表格(“业务”,“其他”)。 我不确定到底出了什么问题。
重要提示,之所以像我这样做有三个表格,是因为我做了三个按钮,分别称为“业务”“支持”“其他”,然后当您单击其中一个按钮时,会出现特定的表格。
内含表单的html脚本。
<!-- 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-->
将消息发送到我的电子邮件的 php 脚本。
支持表单(supFormSend.php):
<?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;
?>
业务表单(busFormSend.php):
<?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;
?>
其他形式(otherFormSend.php):
<?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;
?>
【问题讨论】:
-
您在其他表单的输入元素上缺少“名称”属性。
-
完美!非常感谢。
-
BTW @Fulgut98 为什么不创建一个表单,根据单击的按钮触发某些字段的开/关或隐藏数据?维护起来会更容易!