繁体   English   中英

表单提交后,PHP脚本不发送电子邮件

[英]PHP script does not send the email after form submits

表单提交后,我希望PHP脚本将表单的内容发送到电子邮件。 我有一个类似的PHP脚本,可以链接到一个较小的表单,并且工作正常。 这两个脚本之间的唯一区别是变量。

PHP代码

<?php
    if ($_POST["submit"]) {

         $name=$_POST['name'];
         $address=$_POST['address'];
         $firstContactName=$_POST['firstContactName'];
         $firstContactEmail=$_POST['firstContactEmail'];
         $firstContactPhone=$_POST['firstContactPhone'];
         $secondContactName=$_POST['secondContactName'];
         $secondContactEmail=$_POST['secondContactEmail'];
         $secondContactPhone=$_POST['secondContactPhone'];
         $vehicleOrgName=$_POST['vehicleOrgName'];
         $vehicle1=$_POST['vehicle1'];
         $vehicle2=$_POST['vehicle2'];
         $bus=$_POST['bus'];
         $motorcycle=$_POST['motorcycle'];
         $float=$_POST['float'];
         $horse=$_POST['horse'];
         $marchingunit=$_POST['marchingunit'];

         $subject="Parade Application";

         $body = "From: $name\n
    <br /> Address: $address\n
    <br /> First Contact Name: $firstContactName\n
    <br /> First Contact Email: $firstContactEmail\n
    <br /> First Contact Phone: $firstContactPhone\n
    <br /> Second Contact Name: $secondContactName\n
    <br /> Second Contact Email: $secondContactEmail\n
    <br /> Second Contact Phone: $secondContactPhone\n 
    <br /> Entry Type: $vehicle1\t$vehicle2\t$bus\t$motorcycle\t$float\t$horse\t$marchingunit\n 
    <br /> Organization Name for Magnetic Sign: $vehicleOrgName\n";

        /* Set e-mail recipient */

        $ToEmail = 'cbonnette112@rams.wssu.edu'; 
        $subject = trim($subject);
        $mailheader = "From: cbonnette112@rams.wssu.edu\r\n"; 
        $mailheader .="MIME-Version: 1.0" . "\r\n" . 
        $mailheader .="Content-type: text/html; charset=UTF-8" . "\r\n";
        mail(trim($ToEmail), $subject, $body, $mailheader) or die ('failure'); 
    }
?>

HTML表单代码

<form id="contactForm" name="contact" class="form-horizontal" role="form" method="post" action="">
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">Name of Organization</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="name" name="name" value="" required>
        </div>
    </div>
    <div class="form-group">
        <label for="address" class="col-sm-2 control-label">Organization Address</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="address" name="address" value="" required>
        </div>
    </div>
    <p class="center bold">1st Contact Person</p>
    <div class="form-group">
        <label for="firstContactName" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="firstContactName" name="firstContactName" value="" required>
        </div>
    </div>
    <div class="form-group">
        <label for="firstContactEmail" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-8">
            <input type="email" class="form-control" id="firstContactEmail" name="firstContactEmail" value="" required>
        </div>
    </div>
    <div class="form-group">
        <label for="firstContactPhone" class="col-sm-2 control-label">Telephone</label>
        <div class="col-sm-8">
            <input type="tel" class="form-control" id="firstContactPhone" name="firstContactPhone" value="" required>
        </div>
    </div>
    <p class="center bold">2nd Contact Person</p>
    <div class="form-group">
        <label for="secondContactName" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="secondContactName" name="secondContactName" value="" required>
        </div>
    </div>
    <div class="form-group">
        <label for="secondContactEmail" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-8">
            <input type="email" class="form-control" id="secondContactEmail" name="secondContactEmail" value="" required>
        </div>
    </div>
    <div class="form-group">
        <label for="secondContactPhone" class="col-sm-2 control-label">Telephone</label>
        <div class="col-sm-8">
            <input type="tel" class="form-control" id="secondContactPhone" name="secondContactPhone" value="" required>
        </div>
    </div>
    <hr />
    <p class="center bold">TYPE OF ENTRY</p>
    <div class="form-group center">
        <label class="checkbox-inline"><input type="checkbox" value="" id="vehicle1" name="vehicle1">Vehicle 1</label>
        <label class="checkbox-inline"><input type="checkbox" value="" id="vehicle2" name="vehicle2">Vehicle 2</label>
        <label class="checkbox-inline"><input type="checkbox" value="" id="bus" name="bus">Bus</label>
        <label class="checkbox-inline"><input type="checkbox" value="" id="motorcycle" name="motorcycle">Motorcycle</label>
        <label class="checkbox-inline"><input type="checkbox" value="" id="float" name="float">Float</label>
        <label class="checkbox-inline"><input type="checkbox" value="" id="horse"name="horse">Horse</label>
        <label class="checkbox-inline"><input type="checkbox" value="" id="marchingunit" name="marchingunit">Marching Unit</label>
    </div>
    <div class="form-group center">
        <p class="bold">ORGANIZATION NAME AS YOU WANT IT ON YOUR MAGNETIC SIGN IF REGISTERING A VEHICLE</p>
        <div class="col-sm-8 col-sm-offset-2">
            <input type="text" class="form-control" id="vehicleOrgName" name="vehicleOrgName" value="">
        </div>
    </div>

    <div class="center">
        <p class="center bold">APPLICATION FEE PER ENTRY</p>
        <p>Vehicle - $100 (Includes 2 new signs)</p>
        <p>Bus - $500</p>
        <p>Motorcycle - $100</p>
        <p>Motorcycle and Vehicle - $200</p>
        <p>Float - $70 (Responsible for securing your own float)</p>
        <p>Marching Unit - $35</p>
        <p>Horse - $35</p>
        <p>Marching Unit and Vehicle - $135</p>
        <p style="color:#CE0001">ALL FEES ARE NON-REFUNDABLE</p>
        <p style="color:#CE0001">DO NOT SEND CASH OR PERSONAL CHECKS</p>
    </div>
    <div class="center">
        <p>If mailing, make money orders or cashiers checks payable:</p>
        <p>Winston-Salem State University<br/>
                            C/O <strong>WSSU Homecoming Committee</strong><br />
                            601 MLK Dr.<br />
                            TSC-G05<br />
                            Winston-Salem, NC 27110
        </p>
    </div>

    <h4 class="center" style="color:#CE0001">APPLICATION DEADLINE: Thursday, September 15</h4>
    <hr />

    <div>
        <ol>
            <li>All entries must move at a satisfactory rate of speed or be subject to removal from the parade line.</li>
            <li>All audio must meet City Code.</li>
            <li>No items can be thrown from vehicles.</li>
            <li>Horses must be equipped with diaper buckets. There is a $100.00 refundable deposit required for horse units given as a separate check. This fee will not be refunded if the city has to clean horse waste from the parade route. The entry fee for horse groups ae the same as marching entries, $35.</li>
            <li>All entries are required to attend 1 of 2 pre-parade meetings in person or by teleconferencing.</li>
            <li>No trucks or trailers.</li>
        </ol>
    </div>
    <hr />

    <div class="center">
        <h4>Float Contact Information</h4>
        <p>Clines Floats<br />
            Contact Person: Phyllis Caldwell<br />
            336-830-2063</p>
        <p>Southeastern Float Company<br />
            Contact Person: Denver Wright<br />
            803-917-0644</p>
        <h4>For Additional Information Contact</h4>
        <p>Stephen Powell<br />
            Homecoming Parade Coordinator<br />
            336-750-3386<br />
        <a href="mailto:powellsl@wssu.edu">powellsl@wssu.edu</a></p>
    </div>
    <hr />
    <div class="form-group center">
        <div class="col-sm-8 col-sm-offset-2">
            <button id="submit" name="submit" type="submit" class="btn btn-danger" data-toggle="modal" data-target="#myModal">Submit</button>
        </div>
    </div>
</form>

两件事-您没有为此表单列出操作-如果与表单位于同一php页面中就可以了,因此可以将其重新加载到同一页面中(但是如果您在单独的页面中拥有php,则需要在表单的action属性中指定该位置),然后显示以下行:

<button id="submit" name="submit" type="submit" class="btn btn-danger" data-toggle="modal" data-target="#myModal">Submit</button>

它似乎正在调用模式(“ #myModal”),但是您没有在代码中列出此模式,因此它试图调用模式而不是提交表单,因此阻止设置$ _POST ['submit'] php页面所依赖的。 模式应由表单提交触发,或从此代码行中删除以允许正确的表单提交和电子邮件发送。

<button id="submit" name="submit" type="submit" class="btn btn-danger">Submit</button>

如果要在提交表单后调用模式,则可以使用:

$( "#contactForm" ).submit(function() {
  $('#myModal').modal('show')
});

暂无
暂无

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

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