2013-02-22 86 views
0

目前的外觀將幾乎不具有組織,例如電子郵件:PHP Web表單;當表單提交它的造型外發電子郵件

Name: 
JohnDoe 
email: 
[email protected] 
message: 
blah, blah, blah 

我想在標籤左對齊,和值右對齊並在電子郵件中添加背景圖片。我知道我將需要使用表格;但我在PHP中絕不夠精通。看看代碼,我相信這條帶與外觀有關。我從html-form-guide.com獲得了表單。任何幫助將不勝感激,謝謝。

function FormSubmissionToMail() 
{ 
    $ret_str=''; 
    foreach($_POST as $key=>$value) 
    { 
     if(!$this->IsInternalVariable($key)) 
     { 
      $value = htmlentities($value,ENT_QUOTES,"UTF-8"); 
      $value = nl2br($value); 
      $key = ucfirst($key); 
      $ret_str .= "<div class='label'>$key :</div><div class='value'>$value </div>\n"; 
     } 
    } 
    foreach($this->fileupload_fields as $upload_field) 
    { 
     $field_name = $upload_field["name"]; 
     if(!$this->IsFileUploaded($field_name)) 
     { 
      continue; 
     }   

     $filename = basename($_FILES[$field_name]['name']); 

     $ret_str .= "<div class='label'>File upload '$field_name' :</div><div class='value'>$filename </div>\n"; 
    } 
    return $ret_str; 
} 

function GetMailStyle() 
{ 
    $retstr = "\n<style>". 
    "body,.label, { font-family:Arial,Verdana; } ". 
    ".label {font-weight:bold; margin-top:5px; font-size:1em; color:#000;} ". 
    ".value {margin-bottom:15px;font-size:0.8em;padding-left:5px; font-family:Helvetica;} ". 
    "</style>\n"; 

    return $retstr; 
} 
function GetHTMLHeaderPart() 
{ 
    $retstr = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n". 
       '<html><head><title></title>'. 
       '<meta http-equiv=Content-Type content="text/html; charset=utf-8">'; 
    $retstr .= $this->GetMailStyle(); 
    $retstr .= '</head><body>'; 
    return $retstr; 
} 
function GetHTMLFooterPart() 
{ 
    $retstr ='</body></html>'; 
    return $retstr ; 
} 
function ComposeFormtoEmail() 
{ 
    $header = $this->GetHTMLHeaderPart(); 
    $formsubmission = $this->FormSubmissionToMail(); 
    $footer = $this->GetHTMLFooterPart(); 
    $message = $header."Submission from 'contact us' form:<p>$formsubmission</p><hr/>".$footer; 

    return $message; 
} 
+0

這令我更象是一個CSS/HTML的問題,而不是多用PHP做。 – 2013-02-22 16:54:59

+0

html電子郵件!必須......抵抗......衝動......殺死...... – 2013-02-22 17:07:09

回答

2

不同的電子郵件客戶端的CSS支持真的不同。您的代碼正在將<style>標記中的CSS加載到head標記中。這僅在某些電子郵件客戶端中受支持,所以有些不會加載任何CSS。

我發現包含CSS的支持最廣泛的方法是在每個HTML元素上使用style屬性(是的,這是一個很痛苦的事情)。另外,並不是所有的css規則都被支持。一個方便的指南,電子郵件客戶端支持什麼可以找到here.

另外,請確保您使用正確的電子郵件標題發送HTML郵件與PHP的郵件功能。見example #4

0

,如果你只需要發送電子郵件,它更好地使html.inc並導入這個 與

require(html.inc) 

把變量在文件中併發送電子郵件phpmailer室內用後。

使用這html.inc

相關問題