【问题标题】:Sending information from html form to email将信息从 html 表单发送到电子邮件
【发布时间】:2016-07-02 07:07:30
【问题描述】:

我有一个简单的网站表单,允许用户向我的客户电子邮件地址发送查询/消息。

我正在努力让它发挥作用。到目前为止,我已经设法找到一些代码(也通过堆栈溢出),允许表单在提交时将空白电子邮件发送到正确的地址。我似乎遗漏了一些代码或使提交按钮从表单中提取信息以发送的内容。

下面是我的代码。

谢谢(PS 我没有使用 PHP 的经验,只是为了改变我之前找到的代码来实现这一点)。

<?php
    mail('chameleonyeadon@gmail.com', $_POST['name'], $_POST['email'], $_POST['number'], $_POST['message']);
?>  

<form method="post" action="email.php" enctype="text/plain">
                    <!-- name-->
                    <label class="contact__form--label"><em>What is your name?</em><br> 
                        <input type="text" name="name" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your name here" maxlength="30" required="required"/></label><br>
                    <!-- email-->
                    <label class="contact__form--label"><em>Do you have an email address?</em><br>
                        <input type="email" name="email" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your email address here" maxlength="50" required="required"/></label><br>
                    <!-- number-->
                    <label class="contact__form--label"><em>Can we contact you by phone?</em><br>
                        <input type="number" name="number" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter a phone number we can use here" maxlength="50" required="required"/></label><br>
                    <!-- message--> 
                    <label class="contact__form--label"><em>What is your message?</em><br>
                        <textarea name="message" required="required" class="contact__form__inputbox contact__form__inputbox--marg contact__form__textarea contact__form__inputbox--pad" placeholder="Enter your message here"></textarea></label><br>   
                    <div class="contact__form__btns">
                        <input type="submit" value="Send" class="btn btn--brdr btn--padding--less">
                        <input type="reset" value="Clear" class="btn btn--brdr btn--padding--less btn__formpos">    
                    </div>      
                    </form>

【问题讨论】:

    标签: php html forms email submit


    【解决方案1】:

    首先,您必须删除 action="email.php",因为您将 PHP 代码放在同一个文件中。

    然后,您必须删除 enctype="text/plain" 才能使其正常工作。

    See this stackoverflow subject

    最后,除了required 验证之外,最好在执行邮件功能之前测试 PHP 中发送的内容

    【讨论】:

    • 谢谢,这有效,但仅此而已。它现在在电子邮件主题中发布用户名(正确),然后提供电话号码和电子邮件地址字段。出于某种原因,它遗漏了“消息”文本区域中的任何内容。
    • 检查mail()函数是否格式化:php.net/manual/fr/function.mail.php消息的内容应该在第三个参数上
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 2017-03-31
    • 2014-02-22
    • 2023-04-09
    • 2015-02-11
    相关资源
    最近更新 更多