PHP邮件没有发送返回的空白页面

时间:2015-05-01 10:47:53

标签: php email

这是我的表格。但它没有发送邮件,也没有显示任何错误。发送邮件功能在服务器上工作正常。我如何使其功能,我发现他们的详细信息被插入到表单中,但电子邮件不发送。

 <?php
    ob_start();
    session_start();
    $txtname            = $_POST['txtname']; 
        $txtemail           = $_POST['txtemail'];
        $txtnumber          = $_POST['txtnumber'];
        $cbocountry         = $_POST['cbocountry'];
        $rooms              = $_POST['rooms'];
        $Arrivaldate        = $_POST['Arrivaldate'];
        $departure          = $_POST['departure'];
        $Houseboat          = $_POST['Houseboat'];
        $adults             = $_POST['adults'];
        $children           = $_POST['children'];
        $Bookingdetails     = $_POST['Bookingdetails'];

    $body="<b><u>ANGEL HOUSEBOATS</u></b><br><br>
    <table border=\"0px\" bgcolor=\"#FFFFFF\"> 
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Name &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $txtname</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; E-mail &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $txtemail</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Telephone &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $txtnumber</b></font></td> 
    </tr>

    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Country &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $cbocountry</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; No.of Rooms &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $rooms</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Arrival &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $Arrivaldate</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Departure &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $departure</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Houseboat &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $Houseboat</b></font></td> 
    </tr>

    <tr> 
    <td bgcolor=\"#dcdcdc\" width=\"150px\">&nbsp;&nbsp; Number of People &nbsp;&nbsp;</td><td bgcolor=\"#dcdcdc\"> <font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; No.of Adults : $adults  | &nbsp;&nbsp; No.of Childern : $children</b></font></td> 
    </tr>
    <tr> 
    <td bgcolor=\"#dcdcdc\">&nbsp;&nbsp; Comments </td> <td bgcolor=\"#dcdcdc\"><font face=\"Arial\" size=\"2px\"><b>&nbsp;&nbsp; $Bookingdetails &nbsp;&nbsp;</b></font></td></tr>";

    $headers = "Content-Type: text/html; charset=iso-8859-1"."\r\n"."From: $txtemail" . "\r\n" .
    "Reply-To: $txtemail" . "\r\n"
    ;
    $to="myemail@gmail.com";
    $subject="$txtemail";
    $message="<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2px\"><b>A message has been sent by $txtname ($txtemail). The message is given below:</b></font><br><br><br><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"3 px\">";
    $message.=$body."</font><br><br><br><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2 px\"><b>"."This is a computer generated mail</b></font><br><br><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1px\">www.mydomain.com</font>";

    $mailsent=mail($to, $subject, $message, $headers);
    print_r($mailsent);
    if($mailsent)
    {
    $headers = "Content-Type: text/html; charset=iso-8859-1"."\r\n"."From: Bookings <www.mydomain.com>" . "\r\n" .
    "Reply-To: info@mydomain.com" . "\r\n"
    ;
    $to=$_POST['txtemail'];
    $subject=" HOUSEBOATS!";
    $message="Thanks for choosing <b> HOUSEBOATS</b>.";
    $mailsent=mail($to, $subject, $message, $headers);
    {
    //Clear the Body
    $body = "Message from www.yourdomain.com<br/><br/>
    Thanks for your Message! We will contact you soon.";

    {
        header("Location:success.html");//Change the address 
    }
    }
    }
     ?>   

1 个答案:

答案 0 :(得分:0)

尝试将邮件部分更改为此。将您的$body更改为$message并分成更小的部分以便于控制。

    $headers   = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/html; charset=UTF-8";
    $headers[] = "From: Bookings www.mydomain.com <myemail@gmail.com>"; 
    $headers[] = "Reply-To: Bookings <myemail@gmail.com>";
    $headers[] = "Subject: {$subject}";
    $headers[] = "X-Mailer: PHP/".phpversion();

    $message = "Hello " . $txtname. ",\r\n\n";        
    $message .= "<table border='0px' bgcolor='#FFFFFF'>";
    $message .= "<tr>";
    $message .= "<td bgcolor='#dcdcdc' width='150px'>";
    $message .= "&nbsp;&nbsp; Name &nbsp;&nbsp;</td>";
    $message .= "<td bgcolor='#dcdcdc'> <font face='Arial' size='2px'>";
    $message .= "<b>&nbsp;&nbsp;". $txtname ."</b></font></td>"; 
    $message .= "</tr>";
    $message .= "Best regards,\r\n\r\nJohn Doe (bookings\r\n\r\n";

    mail($txtemail, '=?utf-8?B?'.base64_encode($subject).'?=', $message, implode("\r\n", $headers));