【问题标题】:sand smtp mail php class SMTPClient沙 smtp 邮件 php 类 SMTPClient
【发布时间】:2013-05-14 15:04:06
【问题描述】:

我用 SMTPClient 类邮件 utf-8 发帖,但是我什么都没做! 请帮我收下,谢谢

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;
}


}

///////////////////////////////////////////////////////////////////////
$to = $_POST['to'];
$from =$_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();

我在这里找到了这段代码:http://url.lid.ir/KPyhfU

【问题讨论】:

  • 您是否遇到任何错误?
  • 这也是旧的php类格式...function SMTPClient应该改为public function __construct
  • 所有邮件都已发送,但我想发送需要 utf-8 可读的 utf-8 格式文本
  • 本课将指导你如何改变说话的方式?
  • 对不起,你没有问一个明确的问题,只是粘贴你在网上找到的代码说它不起作用。请提供您收到的实际错误的详细信息以及它如何无法按预期工作

标签: php utf-8 smtp smtpclient


【解决方案1】:

更改 SMTPClient 中 SendMail 方法的定义

function SendMail ($charset = "utf-8", $contentType = "text/plain")
{
    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".
        "Content-Type: ".$contentType."; ".$charset."\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;
} 

【讨论】:

  • 我想使用相同的类但使用 utf8 但我不能使用此代码!
  • 您必须输入一个带有字符集标注的 Content-Type 才能使用 UTF-8。此类为您组装邮件标头,因此唯一的方法是更新类或重载它。您可能想研究更现代的解决方案,例如 Zend_Mail。
【解决方案2】:

我找到了! 终于我找到了! 添加代码非常容易:

$this->subject = "=?UTF-8?B?" . base64_encode(html_entity_decode($this->subject, ENT_COMPAT, 'UTF-8')) . "?=".$subject; 

【讨论】:

    猜你喜欢
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 2017-10-27
    • 2011-04-01
    • 2015-03-16
    • 1970-01-01
    相关资源
    最近更新 更多