2015-02-09 71 views
1

我的服務器每隔一段時間都會向用戶列表發送一封例行郵件。我想要打包成HTML格式。我知道我需要使用$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";或類似的東西,但是我也使用了一段時間我發現的一個小插件,它允許我在發送郵件之前連接到SMTP服務器(所以它不會像收件箱中的垃圾郵件一樣什麼不)。使用SMTPMail插件以HTML格式發送電子郵件

無論如何,任何人都知道我可以如何編輯插件,使其發送爲HTML?

郵件腳本:

include('SMTPconfig.php'); 
include('SMTPClass.php'); 
$emailbody='I\'d like this to send as html'; 
$elist = mysql_query("SELECT email FROM `subs` ORDER BY id ASC"); 
if(mysql_num_rows($elist) > 0) 
    { 
    while($elist_result = mysql_fetch_array($elist)) 
    { 
    $to= $elist_result['email']; 
    $from = '[email protected]'; 
    $subject = $_POST['sub']; 
    $body = $emailbody; 
    $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body); 
    $SMTPChat = $SMTPMail->SendMail(); 
    } 
    exit(); 
    } 

配置文件:

$SmtpServer="mail.chloecrayola.co.uk"; 
$SmtpPort="25"; 
$SmtpUser="[email protected]"; 
$SmtpPass="*******"; 

最後,發送這些電子郵件位。我需要在這裏做出改變,但我不知道我怎麼會做它:

class SMTPClient 
{ 
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body) 
{ 
$this->SmtpServer = $SmtpServer; 
$this->SmtpUser = base64_encode ($SmtpUser); 
$this->SmtpPass = base64_encode ($SmtpPass); 
$this->from = $from; 
$this->to = $to; 
$this->subject = $subject; 
$this->body = $body; 
    if ($SmtpPort == "") 
    { 
    $this->PortSMTP = 25; 
     }else{ 
    $this->PortSMTP = $SmtpPort; 
    } 
} 
function SendMail() 
{ 

    if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) 
    { 

      fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n"); 
      $talk["hello"] = fgets ($SMTPIN, 1024); 

      fputs($SMTPIN, "auth login\r\n"); 
      $talk["res"]=fgets($SMTPIN,1024); 
      fputs($SMTPIN, $this->SmtpUser."\r\n"); 
      $talk["user"]=fgets($SMTPIN,1024); 

      fputs($SMTPIN, $this->SmtpPass."\r\n"); 
      $talk["pass"]=fgets($SMTPIN,256); 

      fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n"); 
      $talk["From"] = fgets ($SMTPIN, 1024); 
      fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n"); 
      $talk["To"] = fgets ($SMTPIN, 1024); 

      fputs($SMTPIN, "DATA\r\n"); 
      $talk["data"]=fgets($SMTPIN,1024); 

      fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n"); 
      $talk["send"]=fgets($SMTPIN,256); 
      //CLOSE CONNECTION AND EXIT ... 
      fputs ($SMTPIN, "QUIT\r\n"); 
      fclose($SMTPIN); 
    } 
return $talk; 
}   
} 

我敢肯定,這一定是可以做到的,但我真的不知道。謝謝

回答

0
Content-Type: multipart/alternative; 
boundary="===boundaryString==" 
MIME-Version: 1.0 

嘗試在$標頭中使用上述MIME標頭。

然後身體需要包括以下內容:

--===boundaryString== 
MIME-Version: 1.0 
Content-Type: text/plain; charset="utf-8" 
Content-Transfer-Encoding: quoted-printable 

... 
text template 
... 

--===boundaryString== 
MIME-Version: 1.0 
Content-Type: text/html; charset="utf-8" 
Content-Transfer-Encoding: quoted-printable 


... 
html template 
... 

它始終是一個很好的做法,包括含有格式爲TXT和HTML作爲相同的信息都TXT和HTML模板。有助於避免垃圾郵件過濾器,並改善整體交付。儘管如此,這並不能代替正確的反向查找設置,其中包括DNS服務器上的SPF,DKIM,DMARK記錄。

+0

我的問題在於,我似乎無法找到修改標題的方法。只要我試圖添加任何與標題相關的東西,就會彈出一大堆(非致命的)錯誤。自發布這個問題以來,我發現了一個新插件來完成這項任務,但如果有人爲此提出了一個答案,它可能在未來有用 – 2015-02-10 03:15:32

+0

您可以嘗試添加我在開始時提出的標題的身體。它應該覆蓋由插件添加的現有標題。 – pdessev 2015-02-12 18:05:22

相關問題