2015-02-09 149 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

相关问题