SMTP 不发送 HTML 消息

发布于 2024-12-05 17:51:09 字数 2028 浏览 1 评论 0原文

早上好,

我正在尝试发送包含 HTML 消息的 SMTP 邮件。但这并没有传达出信息。

所以我做了一个测试。短信发送成功。 Html 消息并发送但收效甚微。

服务器问题是不接受我的帖子 html?

服务器响应:

220 HOST ESMTP
250-HOST
250-PIPELINING
250-SIZE 40960000
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH = PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250 8BITMIME

响应连接。:

 220 HOST ESMTP 
 250-HOST 
 250-PIPELINING 
 250-SIZE 40960000 
 250-ETRN 
 250-STARTTLS 
 250-AUTH PLAIN LOGIN 
 250-AUTH=PLAIN LOGIN 
 250-ENHANCEDSTATUSCODES 
 250 8BITMIME 
 334 VXNlcm5hbWU6 
 334 UGFzc3dvcmQ6 
 235 2.7.0 Authentication successful 
 250 2.1.0 Ok 
 250 2.1.5 Ok 
 354 End data with . 
 250 2.0.0 Ok: queued as 3B74C7E40BA 221 2.0.0 Bye 

我的代码:

private function conx(){
 $this->conxe = fsockopen($smtp_serve, $port, $errno, $errstr, 30) or die('Erro log: smtp 12');
    return true;
 } 


 private function send_email($email_send, $sub, $body_m){
      $this->socket("EHLO ".$smtp_serve."");
      $this->socket("AUTH LOGIN");
      $this->socket(base64_encode($user));
      $this->socket(base64_encode($pass));
      $this->socket("MAIL FROM:" .$smtp_in);
      $this->socket("RCPT TO:" .$email_send);
      $this->socket("DATA");
      $this->socket($this->body($email_send, $sub, $body_m));
      $this->socket(".");
      $this->socket("QUIT");
      fclose($this->socket); 
    }
private function body($email_send, $sub, $body_m){
      $this->co  = "To: ".$email_send." <".$email_send."> \r\n";
      $this->co .= "From: $my_email <$my_email> \r\n";
      $this->co .= "Subject: ".$sub." \r\n";
      $this->co .= "$body_m \r\n";
      $this->co .= "MIME-Version: 1.0 \r\n";
      $this->co .= "Content-Type: text/html; \r\n";
      $this->co .= "charset=\"iso-8859-1\" \r\n";
      return  $this->co;
}

private function socket(){
            return fputs($this->conxe, $string."\r\n"); //fwrite
}

我将非常感谢您的帮助。

Good morning,

I'm trying to send SMTP mail with HTML message. But not this gets the message.

So I did a test. Text messages sent successfully. Html message and sends it with little success.

And server problem that is not accepting my post html?

Server Response:

220 HOST ESMTP
250-HOST
250-PIPELINING
250-SIZE 40960000
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH = PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250 8BITMIME

Response connection.:

 220 HOST ESMTP 
 250-HOST 
 250-PIPELINING 
 250-SIZE 40960000 
 250-ETRN 
 250-STARTTLS 
 250-AUTH PLAIN LOGIN 
 250-AUTH=PLAIN LOGIN 
 250-ENHANCEDSTATUSCODES 
 250 8BITMIME 
 334 VXNlcm5hbWU6 
 334 UGFzc3dvcmQ6 
 235 2.7.0 Authentication successful 
 250 2.1.0 Ok 
 250 2.1.5 Ok 
 354 End data with . 
 250 2.0.0 Ok: queued as 3B74C7E40BA 221 2.0.0 Bye 

My code:

private function conx(){
 $this->conxe = fsockopen($smtp_serve, $port, $errno, $errstr, 30) or die('Erro log: smtp 12');
    return true;
 } 


 private function send_email($email_send, $sub, $body_m){
      $this->socket("EHLO ".$smtp_serve."");
      $this->socket("AUTH LOGIN");
      $this->socket(base64_encode($user));
      $this->socket(base64_encode($pass));
      $this->socket("MAIL FROM:" .$smtp_in);
      $this->socket("RCPT TO:" .$email_send);
      $this->socket("DATA");
      $this->socket($this->body($email_send, $sub, $body_m));
      $this->socket(".");
      $this->socket("QUIT");
      fclose($this->socket); 
    }
private function body($email_send, $sub, $body_m){
      $this->co  = "To: ".$email_send." <".$email_send."> \r\n";
      $this->co .= "From: $my_email <$my_email> \r\n";
      $this->co .= "Subject: ".$sub." \r\n";
      $this->co .= "$body_m \r\n";
      $this->co .= "MIME-Version: 1.0 \r\n";
      $this->co .= "Content-Type: text/html; \r\n";
      $this->co .= "charset=\"iso-8859-1\" \r\n";
      return  $this->co;
}

private function socket(){
            return fputs($this->conxe, $string."\r\n"); //fwrite
}

I would be very grateful for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

死开点丶别碍眼 2024-12-12 17:51:09

尝试这个。它是 mail() 函数的替代函数。

Try this. It's an alternatieve to the mail() function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文