2012-01-19 14 views
0

私は電子メール本文に動的にHTMLテーブルを作成していますが、電子メールではテーブルを表示する代わりにhtmlコードを受け取ります。私を助けてください。 ここに私のコードです。 私のサーバはこのコードを送信メールにのみ対応しています $ email_message = "name:" .clean_string($ name)。 "\ n"; このコードを使用すると助けてください。PHPでHTMLテーブルを使用して電子メールを送信する方法は?

<?php 
require ('class.phpmailer.php'); 

$name = @$_REQUEST['name']; 
//$email = @$_REQUEST['email']; 
$contact = @$_REQUEST['contact']; 
$day = @$_REQUEST['day']; 
$month = @$_REQUEST['month']; 
$year = @$_REQUEST['year']; 
$date_event = @$_REQUEST['date_event']; 
$check = @$_REQUEST['check']; 
$check_score = @$_REQUEST['check_score']; 
$check_service = @$_REQUEST['check_service']; 
$check_product = @$_REQUEST['check_product']; 
$check_scheme = @$_REQUEST['check_scheme']; 
$check_value = @$_REQUEST['check_value']; 
$check_price = @$_REQUEST['check_price']; 



$arr = array($year,$month,$day); 
$doe_event = join("-",$arr); 

[email protected]$_REQUEST['action']; 

$today=getdate(); 
$gday="$today[mday]"; 
$gmonth="$today[mon]"; 
$gyear="$today[year]"; 
$ghour="$today[hours]"; 
$gminutes="$today[minutes]"; 
$gsecond="$today[seconds]"; 
$create_date="$gyear-$gmonth-$gday $ghour:$gminutes:$gsecond"; 

if($action=='add') { 

     $email_to = "your email"; 
     $email_subject = "Message From Website"; 

     $error_message = ""; 
     $email_exp = "^[a-z .'-]+$"; 
     $email_message = "<strong>Contact form</strong><br>"; 

     function clean_string($string) { 
      $bad = array("content-type","bcc:","to:","cc:","href"); 
      return str_replace($bad,"",$string); 
     } 

      //All data In table mail 
      $headers = "From: $ContactPerson<[email protected]*******.co.in> \n"; 
      $headers .= "Reply-To: $to \r\n"; 
      $headers .= "X-Mailer: PHP/". phpversion(); 
      $headers .= "X-Priority: 3 \n"; 
      $headers .= "MIME-version: 1.0\n"; 
      $headers .= "Content-Type: text/html; charset=UTF-8\n";     
$email_message='<table cellspacing="0" cellpadding="0" border="1" align="center"> 
       <tr> 
        <td bgcolor="#99CC00">Name &nbsp;'; 
         $email_message = "Quick enquiry detail."; 
       $email_message = " ".clean_string($name)."\n";'</td> 
       </tr> 
       </table>'; 


      //$email_message .= clean_string($email);    
      //$email_message = "Quick enquiry detail."; 
      $email_message .= "name: ".clean_string($name)."\n"; 
      $email_message .= "contact: ".clean_string($contact)."\n"; 
      $email_message .= "doe: ".clean_string($doe_event)."\n"; 

    if(isset($_REQUEST['check']) && count($_REQUEST['check'])) 
      { 

       $recipient_email_addresses = array 
       (
); 
        foreach($_REQUEST['check'] as $value){ 
       $email_message .= "services: ".clean_string($value)."\n"; 
       }; 

    }    

      // create email headers 
      $email_from="[email protected]*******.co.in"; 

      $headers = 'From: '.$email_from."\r\n". 
      'Reply-To: '.$_REQUEST['email']."\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 
      $mail = new PHPMailer(); 
      $mail->IsSMTP(); 
      $mail->FromName = $_REQUEST['name']; 
      $mail->Host = 'mail.*******.co.in'; 
      $mail->SMTPAuth = true; 
      $mail->Username = '[email protected]********.co.in'; 
      $mail->Password = '********'; 

      $mail->AddAddress("your email", "ADMIN"); 


      $mail->Subject = "Contact Enquiry From www.********.co.in"; 
      $mail->Body = $email_message; 

      if($mail->Send()) 
      { 

    echo "<script>alert('Thank you for quick submit.') </script>"; 
    echo "<script>location.replace('index.php?action=msgsent');</script>";     
       die; 
      } 
      else 
      { 
    echo "<script>alert('There was an error sending the message, Please try again.')</script>"; 
       echo "<script>location.replace('index.php?action=msgerr');</script>";     
       die;      
      } 

    } 

>

+3

[電子メール本文をPHPで送信するにはどうすればいいですか?](http://stackoverflow.com/questions/6160320/how-to-send-html-table-in-email-body- in-php)、最初の3つの文までが表示されます。 – outis

+0

親愛なる神様何が混乱している... – veritas

+0

上記のコードで生成されているHTMLは実際に何を確認しましたか?私はそうは思わない... – DaveRandom

答えて

3

phpmailerのためにそこにある:?

 

$mail->IsHTML(true); //try adding this 
 

参考:Html Mails

-1

w3schools.comを参照してください。 この例では、適切なアイデアを見つけることができます。 お試しください

+2

-1 for w3schools。 http://w3fools.com/ – DaveRandom

+0

@daveRandom - 悪くはなかったsuggesion –

+0

@DaveRandom - huh ... –