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

时间:2018-10-25 02:21:22

标签: php html forms contact-form

我对HTML和CSS相对满意,但是目前正在为客户构建一个基本站点。他们需要一个联系表,将输入的数据发送到特定的电子邮件地址。我知道这需要PHP,但是我对此并不精通。我已经接近测试文件以使它正常工作,但是没有运气。

如何使它正常工作并发送包含结果的电子邮件?提前致谢! You can find the live page here

这是我在文档顶部的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>

这是我的表单代码:

<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>

1 个答案:

答案 0 :(得分:-1)

您链接到的页面的扩展名为.html,并且您正在尝试在其上运行PHP脚本。

您需要将contact.html重命名为contact.php