php邮件中的空格问题 [英] Problems with spaces in php mails

查看:240
本文介绍了php邮件中的空格问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



简而言之:


  1. 加载html模板文件 fopen

  2. 替换一些值,标记为这样%密码具有实际值 str_replace

  3. 通过以下功能发送邮件,其中 $ content 是加载的html模板文件:

public function send($ receiver,$ subject,$内容){

  $ header =From:。 \\\
;
$ header。=MIME-Version:1.0。 \\\
;
$ header。=Content-type:text / html; charset = utf-8。 \\\
;

$ mailText = $ content;
mail($ receiver,$ subject,stripslashes(iconv('utf-8','iso-8859-1',$ mailText)),$ header);

}

服务器是debian with postfix。



邮件模板以

 < html> < body style =background-color:#fff> < table border =0... 

事情是,我无法重现,在某些情况下,我可以在邮件中找到几个空格,我没有放在那里。最麻烦的是用户和密码字符串中的那些。



其他似乎正确!编码是确定的,html被接受,所有邮件都可以被传递...



密码生成:

  public static function create_password($ length = 12){
$ characters = array(a,b,c d,e,f,g,h,k,m,n,p,q,r,s ,u,v,w,x,y,z,0,1,2,3,4 6,7,8,9,_);
$ password =; $($ i = 0; $ i $ $; $ i ++)
{
$ index = rand(1,count($ characters))-1;
$ password。= $ characters [$ index];
}
$ password = str_replace(__,_,$ password);
返回$密码;
}

任何想法,从哪里开始我的搜索?



是模板,str_replace,postifix,客户端,...?



解决方案

我将开始将HTML保存到一个单独的文件中,并使用浏览器打开。


如果你看到空格,那就是HTML。



如果看起来不错,邮件就会被破坏。 / p>



Mangling



这经常是因为你的行太长,邮件服务器可以使用长度超过80列(古老标准)的线条做出时髦的东西。



为了防止破坏,我建议如下:


  1. 添加标题内容转移编码:base64


  2. 在整个电子邮件内容中应用 chunk_split(base64_encode(...))



I am having some serious problem with some e-mail issue.

in short:

  1. loading a html template file fopen
  2. replacing some values, marked like this %password with real values str_replace
  3. sending mail via the following function, where $content is the loaded html template file:

public function send($receiver, $subject, $content){

    $header = "From:".sender. "\n";
    $header .= "MIME-Version:1.0" . "\n";
    $header .= "Content-type:text/html;charset=utf-8" . "\n";

    $mailText = $content;
    mail($receiver, $subject, stripslashes(iconv('utf-8', 'iso-8859-1', $mailText)) , $header);

}

the server is debian with postfix.

The Mail template starts with

<html> <body style="background-color: #fff;"> <table border="0"...

The thing is, and I cannot reproduce it, that in some cases I can find several spaces in the mail, which I didn't put there. Most problematical are those in the user and password string.

Evering else seems correct! The encoding is ok, the html is accepted, all mails can be delivered ...

password generation:

public static function create_password($length = 12) {
        $characters = array("a", "b", "c", "d", "e", "f", "g", "h", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "_");
        $password = "";
        for($i=0; $i<$length; $i++) {
            $index = rand(1, count($characters)) -1;
            $password .= $characters[$index];
        }
        $password = str_replace("__","_", $password);
        return $password;
    }

Any Ideas, where to start my search?

Is it the template, str_replace, the postifix, the client, ... ?

Thanks so far

解决方案

I would start by saving the HTML into a separate file and open that with a browser.

If you see spaces, it's the HTML.

If it looks fine, the mail gets mangled.

Mangling

This is often caused because your lines are simply too long and mail servers do funky stuff with lines longer than 80 columns (ancient standards).

To prevent mangling I would suggest the following:

  1. Add header Content-Transfer-Encoding: base64.

  2. Apply chunk_split(base64_encode(...)) over the whole e-mail content.

这篇关于php邮件中的空格问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆