简体   繁体   English

发送到电子邮件问题的基本 PHP 表单

[英]Basic PHP Form sent to Email Troubles

I am relatively comfortable with HTML and CSS, but am currently building a basic site for a client.我对 HTML 和 CSS 比较熟悉,但目前正在为客户构建一个基本站点。 They want a contact form that sends the data entered to a specific email address.他们想要一个联系表单,将输入的数据发送到特定的电子邮件地址。 I know this requires PHP, but I am not well-versed in that.我知道这需要 PHP,但我对此并不精通。 I have gotten close with test files to getting this working, but no luck.我已经接近测试文件以使其正常工作,但没有运气。

How can I get this to work properly and send an email with the results?我怎样才能让它正常工作并发送带有结果的电子邮件? Thanks in advance!提前致谢! You can find the live page here你可以在这里找到实时页面

This is my PHP code at the top of the document这是我在文档顶部的 PHP 代码

<?php
if(isset($_POST['submit'])) {
        $name = $_POST['input_1.3'];
        $subject = "Thrive – Contact Us Submission";
    $mailFrom = $_POST['input_2'];
    $message = $_POST['input_5'];
        $phone = $_POST['input_3'];
        $company = $_POST['input_2_6'];
        $selected = $_POST['input_4'];
        $mailTo = "dsebo@ra.rockwell.com";
        $headers = "From: ".$mailFrom;
        $txt = "You have receive a contact request from: ".$name.".\n";
        $txt = "Email Address: ".$mailFrom.".\n";
        $txt = "Phone Number: ".$phone.".\n";
        $txt = "Company Name: ".$company.".\n";
        $txt = "I Am A: ".$selected.".\n\n" .$message;
    mail($mailTo, $subject, $txt, $headers);
        header("Location: index.php?mailsend");
}
?>
<!DOCTYPE html>

This is my form code:这是我的表单代码:

<form method='post' enctype='multipart/form-data' target='gform_ajax_frame_2' id='gform_2'  action='/contact-us/#gf_2'>
                        <div class='gform_body'>
                            <ul id='gform_fields_2' class='gform_fields top_label form_sublabel_below description_below'>
                                <li id='field_2_1'  class='gfield gfield_contains_required field_sublabel_above field_description_below gfield_visibility_visible'>
                                    <fieldset aria-required='true' class='gfieldset'>
                                        <legend class='gfield_label'>Required<span class='gfield_required'> * <span class='sr-only'> Required</span></span></legend>
                                        <div class='ginput_complex ginput_container no_prefix has_first_name no_middle_name has_last_name no_suffix gf_name_has_2 ginput_container_name gfield_trigger_change' id='input_2_1'>
                                            <span id='input_2_1_3_container' class='name_first'>
                                                <label for='input_2_1_3'>Full Name<span class='gfield_required'> * <span class='sr-only'> Required</span></span></label>
                                                <input class='form-control' type='text' name='input_1.3' id='input_2_1_3' value='' aria-label='First name'   aria-required="true" aria-invalid="false" />
                                            </span>

                                        </div>
                                    </fieldset>
                                </li>
                                <li id='field_2_2'  class='gfield gf_left_half gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' >
                                    <label class='gfield_label' for='input_2_2' >Email<span class='gfield_required'> * <span class='sr-only'> Required</span></span></label>
                                    <div class='ginput_container ginput_container_email'>
                                        <input name='input_2' id='input_2_2' type='text' value='' class='form-control medium'     aria-required="true" aria-invalid="false"/>
                                    </div>
                                </li>
                                <li id='field_2_3'  class='gfield gf_right_half field_sublabel_below field_description_below gfield_visibility_visible' >
                                    <label class='gfield_label' for='input_2_3' >Phone</label>
                                    <div class='ginput_container ginput_container_phone'>
                                        <input name='input_3' id='input_2_3' type='text' value='' class='form-control medium'     aria-invalid="false" />
                                    </div>
                                </li>
                                <li id='field_2_6'  class='gfield field_sublabel_below field_description_below gfield_visibility_visible' >
                                    <label class='gfield_label' for='input_2_6' >Company Name</label>
                                    <div class='ginput_container ginput_container_text'>
                                        <input name='input_6' id='input_2_6' type='text' value='' class='form-control medium'      aria-invalid="false" />
                                    </div>
                                </li>
                                <li id='field_2_4'  class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' >
                                    <label class='form-check-label' class='gfield_label'>I am a:<span class='gfield_required'> * <span class='sr-only'> Required</span></span></label>
                                    <div class='ginput_container ginput_container_radio'>
                                        <ul class='gfield_radio' id='input_2_4'>
                                            <li style="padding-left: 1.25rem !important;" class='form-check gchoice_2_4_0'>
                                                <input style="position: absolute; margin-top: .3rem; margin-left: -1.2rem;" class='form-check-input' name='input_4' type='radio' value='Employer'  id='choice_2_4_0'     />
                                                <label class='form-check-label' for='choice_2_4_0' id='label_2_4_0'>Employer</label>
                                            </li>
                                            <li style="padding-left: 1.25rem !important;" class='form-check gchoice_2_4_1'>
                                                <input style="position: absolute; margin-top: .3rem; margin-left: -1.2rem;" class='form-check-input' name='input_4' type='radio' value='Employee'  id='choice_2_4_1'     />
                                                <label class='form-check-label' for='choice_2_4_1' id='label_2_4_1'>Employee</label>
                                            </li>
                                            <li style="padding-left: 1.25rem !important;" class='form-check gchoice_2_4_3'>
                                                <input style="position: absolute; margin-top: .3rem; margin-left: -1.2rem;" class='form-check-input' name='input_4' type='radio' value='Other'  id='choice_2_4_3'     />
                                                <label class='form-check-label' for='choice_2_4_3' id='label_2_4_3'>Other</label>
                                            </li>
                                        </ul>
                                    </div>
                                </fieldset>
                            </li>
                            <li id='field_2_5'  class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' >
                                <label class='gfield_label' for='input_2_5' >Message<span class='gfield_required'> * <span class='sr-only'> Required</span></span></label>
                                <div class='ginput_container ginput_container_textarea'>
                                    <textarea name='input_5' id='input_2_5' class='form-control textarea medium'    aria-required="true" aria-invalid="false"   rows='10' cols='50'></textarea>
                                </div>
                            </li>
                            <li id='field_2_7'  class='gfield gform_validation_container field_sublabel_below field_description_below gfield_visibility_visible' >
                                <label class='gfield_label' for='input_2_7' >Phone</label>
                                <div class='ginput_container'>
                                    <input aria-describedby='field_2_7_dmessage' name='input_7' id='input_2_7' type='text' value='' />
                                </div>
                                <div id='field_2_7_dmessage' class='gfield_description'>This field is for validation purposes and should be left unchanged.</div>
                            </li>
                        </ul>
                    </div>
                    <div class='gform_footer top_label'>
                        <button type="submit" id="gform_submit_button_2" onclick='if(window["gf_submitting_2"]){return false;}  window["gf_submitting_2"]=true;  ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_2"]){return false;} window["gf_submitting_2"]=true;  jQuery("#gform_2").trigger("submit",[true]); }' class="gform_button btn btn-primary">Submit</button>
                        <input type='hidden' name='gform_ajax' value='form_id=2&amp;title=&amp;description=&amp;tabindex=0' />
                        <input type='hidden' class='gform_hidden' name='is_submit_2' value='1' />
                        <input type='hidden' class='gform_hidden' name='gform_submit' value='2' />
                        <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' />
                        <input type='hidden' class='gform_hidden' name='state_2' value='WyJbXSIsImFkMjMzYWUxMGM1YjYxNzhjNGQzYjJlNGUwNzFiODFlIl0=' />
                        <input type='hidden' class='gform_hidden' name='gform_target_page_number_2' id='gform_target_page_number_2' value='0' />
                        <input type='hidden' class='gform_hidden' name='gform_source_page_number_2' id='gform_source_page_number_2' value='1' />
                        <input type='hidden' name='gform_field_values' value='' />
                    </div>
                </form>

The page you have linked to has an .html file extension, and you're trying to run a PHP script on it.您链接到的页面具有.html文件扩展名,并且您正在尝试在其上运行 PHP 脚本。

You'll want to rename contact.html to contact.php .您需要将contact.html重命名为contact.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM