-1

I SMTPClient class mail utf-8 post, but I did not do anything! Please Help me get thank you

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();

I found this code here: http://url.lid.ir/KPyhfU

2 Answers2

0

Change the defintion of the SendMail method in the SMTPClient

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;
} 
Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • I want to use the same class but with utf8 but I can not use this code! – Saeid Ghaznavi May 14 '13 at 15:39
  • you have to put in a Content-Type with a charset callout to get UTF-8 going. This class assembles the mail header for you so the only way to do that is to update the class or overload it. You might want to look into a more modern solution like Zend_Mail. – Orangepill May 14 '13 at 15:47
0

I found it! Finally I found it! It's very easy to add on Code:

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