2016-04-04 4 views
-1

私のサイトにはフォームがあり、それはテーブルとしてやって来る必要がありますが、どうやってそれを行うのがうまくいかないようです。PHPmailer HTMLテーブル

私は多くのPHPの経験がないので、どんな助けが素晴らしいだろう。 これは私のコードです。

<?php 

require_once('phpmailer/PHPMailerAutoload.php'); 

$toemails = array(); 

$toemails[] = array(
      'email' => '[email protected]', // Your Email Address 
      'name' => 'xxxxxxxxx' // Your Name 
     ); 

// Form Processing Messages 
$message_success = 'We have <strong>successfully</strong> received your  Message and will get Back to you as soon as possible.'; 

// Add this only if you use reCaptcha with your Contact Forms 
$recaptcha_secret = 'xxxxxxxxxxxxxxx'; // Your  reCaptcha Secret 

$mail = new PHPMailer(); 

// If you intend you use SMTP, add your SMTP Code after this Line 


if($_SERVER['REQUEST_METHOD'] == 'POST') { 
if($_POST['template-contactform-email'] != '') { 

    $name = isset($_POST['template-contactform-name']) ? $_POST['template- contactform-name'] : ''; 
    $email = isset($_POST['template-contactform-email']) ?  $_POST['template-contactform-email'] : ''; 
    $phone = isset($_POST['template-contactform-phone']) ? $_POST['template-contactform-phone'] : ''; 
    $subject = isset($_POST['template-contactform-subject']) ? $_POST['template-contactform-subject'] : '';   
    $vesselname = isset($_POST['template-contactform-vesselname']) ? $_POST['template-contactform-vesselname'] : ''; 
    $vesseltype1 = isset($_POST['template-contactform-vesseltype1']) ? $_POST['template-contactform-vesseltype1'] : ''; 
    $vesseltype2 = isset($_POST['template-contactform-vesseltype2']) ? $_POST['template-contactform-vesseltype2'] : ''; 
    $booking1 = isset($_POST['template-contactform-booking1']) ? $_POST['template-contactform-booking1'] :''; 
    $booking2 = isset($_POST['template-contactform-booking2']) ? $_POST['template-contactform-booking2'] :''; 
    $makemodel = isset($_POST['template-contactform-makemodel']) ? $_POST['template-contactform-makemodel'] :''; 
    $vlength = isset($_POST['template-contactform-vlength']) ? $_POST['template-contactform-vlength'] :''; 
    $vbeam = isset($_POST['template-contactform-vbeam']) ? $_POST['template-contactform-vbeam'] :''; 
    $vdraft = isset($_POST['template-contactform-vdraft']) ? $_POST['template-contactform-vdraft'] :''; 
    $eta = isset($_POST['template-contactform-eta']) ? $_POST['template-contactform-eta'] :''; 
    $etd = isset($_POST['template-contactform-etd']) ? $_POST['template-contactform-etd'] :''; 
    $reglocation = isset($_POST['template-contactform-reglocation']) ? $_POST['template-contactform-reglocation'] :''; 
    $regnumber = isset($_POST['template-contactform-regnumber']) ? $_POST['template-contactform-regnumber'] :''; 
    $regexp = isset($_POST['template-contactform-regexp']) ? $_POST['template-contactform-regexp'] :''; 
    $inscompany = isset($_POST['template-contactform-inscompany']) ? $_POST['template-contactform-inscompany'] :''; 
    $insnumber = isset($_POST['template-contactform-insnumber']) ? $_POST['template-contactform-insnumber'] :''; 
    $insexp = isset($_POST['template-contactform-insexp']) ? $_POST['template-contactform-insexp'] :''; 
    $cover = isset($_POST['template-contactform-cover']) ? $_POST['template-contactform-cover'] :''; 
    $elrequire = isset($_POST['template-contactform-elrequire']) ? $_POST['template-contactform-elrequire'] :''; 
    $specrequire = isset($_POST['template-contactform-specrequire']) ? $_POST['template-contactform-specrequire'] :''; 



    $subject = isset($subject) ? $subject : 'New Message From Contact Form'; 

    $botcheck = $_POST['template-contactform-botcheck']; 

    if($botcheck == '') { 

     $mail->SetFrom($email , $name); 
     $mail->AddReplyTo($email , $name); 
     foreach($toemails as $toemail) { 
      $mail->AddAddress($toemail['email'] , $toemail['name']); 
     } 
     $mail->Subject = $subject; 

     $name = isset($name) ? "Name: $name<br><br>" : ''; 
     $email = isset($email) ? "Email: $email<br><br>" : ''; 
     $phone = isset($phone) ? "Phone: $phone<br><br>" : ''; 
     $booking1 = isset($booking1) ? "Booking: $booking1<br><br>" : ''; 
     $booking2 = isset($booking2) ? "Booking: $booking2<br><br>" : ''; 
     $vesselname = isset($vesselname) ? "Vessel Name: $vesselname<br> <br>" : ''; 
     $vesseltype1 = isset($vesseltype1) ? "Vessel Type: $vesseltype1<br> <br>" : ''; 
     $vesseltype2 = isset($vesseltype2) ? "Vessel Type: $vesseltype2<br> <br>" : ''; 
     $makemodel = isset($makemodel) ? "Make and Model: $makemodel<br> <br>" : ''; 
     $vlength = isset($vlength) ? "Vessel Length (m): $vlength<br><br>" : ''; 
     $vbeam = isset($vbeam) ? "Vessel Beam (m): $vbeam<br><br>" : ''; 
     $vdraft = isset($vdraft) ? "Vessel Draft (m): $vdraft<br><br>" : ''; 
     $eta = isset($eta) ? "Estimated Time of Arrival: $eta<br><br>" : ''; 
     $etd = isset($etd) ? "Estimated Time of Departure: $etd<br><br>" : ''; 
     $reglocation = isset($reglocation) ? "Place of Registration: $reglocation<br><br>" : ''; 
     $regnumber = isset($regnumber) ? "Registration Number: $regnumber<br><br>" : ''; 
     $regexp = isset($regexp) ? "Registration Expiry: $regexp<br><br>" : ''; 
     $inscompany = isset($inscompany) ? "Insurance Company: $inscompany<br><br>" : ''; 
     $insnumber = isset($insnumber) ? "Insurance Policy Number: $insnumber<br><br>" : ''; 
     $insexp = isset($insexp) ? "Insurance Expiry: $insexp<br><br>" : ''; 
     $cover = isset($cover) ? "Cover Incl. 10m PL: $cover<br><br>" : ''; 
     $elrequire = isset($elrequire) ? "Electricity Requirements: $elrequire<br><br>" : ''; 
     $specrequire = isset($specrequire) ? "Special Requirements: $specrequire<br><br>" : ''; 


     $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : ''; 

     $body = "$name $email $phone $booking1 $booking2 $vesselname $vesseltype1 $vesseltype2 $makemodel $vlength $vbeam $vdraft $eta $etd $reglocation $regnumber $regexp $inscompany $insnumber $insexp $cover $elrequire $specrequire $referrer"; 

     // Runs only when File Field is present in the Contact Form 
     if (isset($_FILES['template-contactform-file']) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK) { 
      $mail->IsHTML(true); 
      $mail->AddAttachment($_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name']); 
      $mail->AddAttachment($_FILES['template-contactform-file2']['tmp_name'], $_FILES['template-contactform-file2']['name']);    
     } 

     // Runs only when reCaptcha is present in the Contact Form 
     if(isset($_POST['g-recaptcha-response'])) { 
      $recaptcha_response = $_POST['g-recaptcha-response']; 
      $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response); 

      $g_response = json_decode($response); 

      if ($g_response->success !== true) { 
       echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }'; 
       die; 
      } 
     } 

     $mail->MsgHTML($body); 
     $mail->IsHTML(true) 
     $sendEmail = $mail->Send(); 

     if($sendEmail == true): 
      echo '{ "alert": "success", "message": "' . $message_success . '" }'; 
     else: 
      echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }'; 
     endif; 
    } else { 
     echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }'; 
    } 
} else { 
    echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }'; 
} 
} else { 
echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }'; 
} 

?> 

正確に私はテーブルhtmlを追加しますが、どうすれば実装できますか?

$body = ' 
     <html> 
     <head> 
      <title>Some title</title> 
     </head> 
     <body> 
     <table> 
      <tr><td>Name</td><td>'.$Name.'</td></tr> 
      <tr><td>Email</td><td>'.$email.'</td></tr> 
      <tr><td>Phone</td><td>'.$phone.'</td></tr> 
      <tr><td>Booking</td><td>'.$booking1.'</td></tr> 
      <tr><td>Booking</td><td>'.$booking2.'</td></tr> 
     </table> 
     </body> 
     </html>'; 

私は、この表を追加しましたが、それはこの方法では、HTMLを追加し、私はそれをテストしていないチェック THis is the resultant email

+0

どこがhtmlですか?どのようなエラーがありますか? –

+0

エラーはありません。フォームを表示するためにHTMLテーブルを追加する必要があります。 –

+0

yaはhtmlを共有してください –

答えて

0

のように判明しました。

$body = "<html>\n"; 
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n"; 
$body = $message; 
$body .= "</body>\n"; 
$body .= "</html>\n"; 
関連する問題