php – 电子邮件表单问题

前端之家收集整理的这篇文章主要介绍了php – 电子邮件表单问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有三个电子邮件表单,允许用户向我的三封电子邮件发送邮件,而无需自己编写电子邮件.表单正在发送电子邮件,问题是电子邮件发件人和电子邮件信息等信息仅适用于我的“支持”表单,但不适用于其他两种表单(“业务”,“其他” “).
我不知道究竟是错的.

重要的注意事项,原因有三种形式,如我所做的,是因为我已经做了三个按钮,称为“业务”“支持”“其他”,然后当您单击其中一个按钮时,将显示特定的表单.

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,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,send an email to other@myemail.com');
        window.location = 'contact.html';
    </script>
<?PHP
}
header('Location: index.html');
exit;
?>
HTML表单依赖于name属性将数据发布到后端(在本例中为PHP).

当您在PHP中引用变量$_POST [‘nameInput’]时,它的值将以name属性为“nameInput”的形式获取该字段的值.例如,< input type =“text”id =“nameInput”name =“nameInput”/&gt ;. 您的表单#contactSupportForm正在运行,因为您为PHP中引用的值设置了名称属性. 要使其他两种工作方式在HTML中添加所有输入的name属性(并确保name属性的值与您在PHP中引用的值相匹配)就像在ContactSupportForm中一样.

猜你在找的PHP相关文章