PHP电子邮件表单未发送,打印错误

PHP电子邮件表单未发送,打印错误,php,forms,email,Php,Forms,Email,提交表单后,php代码将在底部打印错误消息,而不是发送电子邮件。我不确定代码中的问题在哪里 <?php if (strtolower($_POST['code']) != 'opencom') { die('Error. Please type the word 'OPENCOM' in the appropriate field again'); } if (isset($_POST['submit'])) { $to = "rall

提交表单后,php代码将在底部打印错误消息,而不是发送电子邮件。我不确定代码中的问题在哪里

     <?php

if (strtolower($_POST['code']) != 'opencom')
    {
    die('Error. Please type the word 'OPENCOM' in the appropriate field again');
    }

if (isset($_POST['submit']))
    {
    $to = "rally@lacesusa.org";
    $subject = "2015 Rally Registration";
    $VehicleType_field = $_POST['VehicleType'];
    $PilotName_field = $_POST['PilotName'];
    $PilotEmail_field = $_POST['PilotEmail'];
    $PilotCell_field = $_POST['PilotCell'];
    $CoPilotName_field = $_POST['CoPilotName'];
    $CoPilotEmail_field = $_POST['CoPilotEmail'];
    $CoPilotCell_field = $_POST['CoPilotCell'];
    $VehicleInfo_field = $_POST['VehicleInfo'];
    $VehiclePlates_field = $_POST['VehiclePlates'];
    $POP_field = $_POST['POP'];
    $body = "Vehicle Type: $VehicleType_field\n Pilot Name: $PilotName_field\n Pilot E-mail: $PilotEmail_field\n Pilot Cell: $PilotCell_field\n Co Pilot Name: $CoPilotName_field\n Co Pilot E-mail: $CoPilotEmail_field\n Co Pilot Cell: $CoPilotCell_field\n Vehicle Info: $VehicleInfo_field\n Vehicle Plates: $VehiclePlates_field\n Proof of Purchase: $POP_field\n";
    $success = mail($to, $subject, $body);
    }

if ($success)
    {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.lacesusa.org/rallythanks\"-->
    <html>
      <head>
        <meta content="text / html;
    charset = windows - 1252" http-equiv="content - type">
      </head>
      <body>";
    }
  else
    {
    echo "Sorry error please try again...";
    } ?> < / body > < / html >

试试这个

    <?php 
         if (strtolower($_POST['code']) != 'opencom') 
           die('Error. Please type the word 'OPENCOM' in the appropriate field again');                      
         if(isset($_POST['submit'])) { 
           $to = "rally@lacesusa.org"; 
           $subject = "2015 Rally Registration";
           $VehicleType_field = $_POST['VehicleType'];                         
           $PilotName_field = $_POST['PilotName'];
           $PilotEmail_field = $_POST['PilotEmail'];  
           $PilotCell_field = $_POST['PilotCell']; 
           $CoPilotName_field = $_POST['CoPilotName']; 
           $CoPilotEmail_field = $_POST['CoPilotEmail']; 
           $CoPilotCell_field = $_POST['CoPilotCell'];                       
           $VehicleInfo_field = $_POST['VehicleInfo']; 
           $VehiclePlates_field = $_POST['VehiclePlates']; 
           $POP_field = $_POST['POP'];  
           $body = "Vehicle Type: $VehicleType_field \n Pilot Name: $PilotName_field \n Pilot E-mail: $PilotEmail_field \n Pilot Cell: $PilotCell_field \n Co Pilot Name: $CoPilotName_field \n Co Pilot E-mail: $CoPilotEmail_field \n Co Pilot Cell: $CoPilotCell_field \n Vehicle Info: $VehicleInfo_field \n Vehicle Plates: $VehiclePlates_field \n Proof of Purchase: $POP_field\n";   

        if (@mail($to, $subject, $body)){ 
            print '<meta http-equiv=\"refresh\" content=\"0;URL=http://www.lacesusa.org/rallythanks\">
            <html> <head> <meta content="text/html; charset=windows-1252" http-equiv="content-type">
          </head> <body>'; 
        } 
        else { echo "Sorry error please try again...";
        }
    } ?>
          </body>
        </html>


这是打印时出现的错误:;}否则{echo“对不起,错误,请重试…”;}使用try-catch并向我更新有关错误的信息。。我希望你在主机上使用它。你不是在本地主机上使用它。。尝试{mail($to,$subject,$body);}catch(异常$x){echo$x->getMessage();}是否有语法错误?您的代码中有太多未转义的引号。未使用本地主机,页面和脚本已启动。请在print语句附近应用single quot,现在html元素不被视为字符串,不是吗…我在另一个页面上使用了类似的代码,该代码与“;}else{echo”抱歉,错误,请重试…;}?>