2010-04-01 4 views
0

나는 지금 PHP native mail() 메소드를 통해 대상 이메일에 정보를 보내고 있습니다. 그 밖의 모든 것은 잘 작동하지만 테이블 부분이 가장 문제가됩니다. 샘플 출력보기 :이메일 본문에 html 테이블을 포함하는 방법

Dear Michael Mao : 
Thank you for purchasing flight tickets with us, here is your receipt : 

Your tickets will be delivered by mail to the following address : 
Street Address 1 : sdfsdafsadf sdf 
Street Address 2 : N/A 
City : Sydney State : nsw Postcode : 2 
Country : Australia 
Credit Card Number : *************1234 

Your purchase details are recorded as : 

<table><tr><th class="delete">del?</th><th class="from_city">from</th><th class="to_city">to</th><th class="quantity">qty</th><th class="price">unit price</th><th class="price">total price</th></tr><tr class="evenrow" id="Sydney-Lima"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Lima</td><td>1</td><td>1030.00</td><td>1030</td></tr><tr class="oddrow" id="Sydney-Perth"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Perth</td><td>3</td><td>340.00</td><td>1020</td></tr><tr class="totalprice"><td colspan="5">Grand Total Price</td><td id="grandtotal">2050</td></tr></table> 

표 소스는 웹 페이지에서 직접 가져온 것입니다. 그러나 Gmail, Hotmail 및 대부분의 다른 이메일은이를 테이블로 렌더링하기 위해 무시됩니다.

Outlook이나 다른 이메일로 에이전트 소프트웨어를 보내지 않고도 PHP mail() 메소드를위한 내장 테이블을 어떻게 만들 수 있을까요?

현재 코드는 테이블 생성에 해당

$purchaseinfo = $_POST["purchaseinfo"]; 
//if html tags are not to be filtered in the body of email 
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>"; 

//must send json response back to caller ajax request 
if(mail($email, 'Your purchase information on www.hardlyworldtravel.com', $emailbody, $headers)) 
    echo json_encode(array("feedback"=>"successful")); 
else echo json_encode(array("feedback"=>"error")); 

어떤 힌트 및 제안을 환영합니다, 미리 감사.

편집 :

$headers = 'From: [email protected]' . "\r\n" . 
     'Reply-To: [email protected]' . "\r\n" . 
     'X-Mailer: PHP/' . phpversion(); 

//carft body of email to a human readable format 
function buildEmailBody() 
{ 
    global $firstname, $lastname, $address1, $address2, $city, $state, $postcode, $country, 
     $cardnum, $email, $purchaseinfo; 

$stringBuilder = "";  // * there is not such a thing as string builder in PHP 

$stringBuilder .= "Dear " .$firstname ." " .$lastname ." :\n"; 
$stringBuilder .= "Thank you for purchasing flight tickets with us, here is your receipt :\n\n"; 
$stringBuilder .= "Your tickets will be deliverd by mail to the following address : \n"; 
$stringBuilder .= "Street Address 1 : " .$address1 ."\n"; 
$stringBuilder .= ($address2!="") ? "Street Address 2 : " .$address2 ."\n" : "Street Address 2 : N/A\n"; 
$stringBuilder .= "City : " .$city; 
$stringBuilder .= ($state!="") ? "State : " .$state : "State : N/A "; 
$stringBuilder .= "Postcode : " .$postcode ."\n"; 
$stringBuilder .= "Country : " .$country ."\n"; 
$stringBuilder .= "Credit Card Number : " .$cardnum ."\n\n"; 
$stringBuilder .= "Your purchase details are recorded as : \n\n"; 

//if html tags are not to be filtered in the body of email 
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>"; 

//otherwise this will be painful to retrieve info out of the html table. 
return $stringBuilder; 
} 
+0

당신이 보여줄 수는? –

+0

@ 페카 : 죄송합니다. 코드를 추가하는 것을 잊어 버렸습니다. 질문을 업데이트 할 것입니다. –

답변

0

PHP의 웹 사이트는 메일을 보내기에 섹션이, 예를 들면 # 4는 HTML 형식의 이메일을 보낼 헤더를 변경하는 방법을 보여줍니다.

PHP manual on using mail

여기에 테이블이 실제로 전자 메일 ($의 emailbody)에 넣고 당신이 필요로하는 코드의 핵심 부분 ...

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
+0

@Zachary : 이것을 지적 해 주셔서 감사합니다. 나는 평문, 다른 html 페이지가 아니라는 것을 잊고있다. –

1

할 수 있습니다 일반 텍스트 이메일로하지 "삽입"는 HTML 테이블. 하나의 유형일 수 있습니다.
이메일에 HTML 표를 추가하려면 HTML 형식의 전체 글자를 만들고 Content-type 메일 헤더를 text/html으로 설정해야합니다.

1

다른 포스터에서 말한 것처럼 전자 메일을 일반 텍스트가 아닌 HTML 형식으로 보내야합니다.

배 Mail_Mime 패키지는 보내는 HTML 이메일은 매우 간단합니다 :

http://pear.php.net/package/Mail_Mime/

+0

@ ericofsac :이 팁을 가져 주셔서 감사합니다! 유니 할당 마커 때문에, 나는 내 손으로 모든 것을 만드는 게으름이다. –

관련 문제