Archive

Archive for April, 2006

终于能够通过phpmailer使用gmail账号发送邮件了

April 14th, 2006 Fwolf 38 comments

phpmailer(现在的版本是1.73)是一个很好用的工具,可以很方便的使用php语言发送邮件,支持smtp及验证,我们一直都用它。

但是,由于gmail的smtp采用了ssl连接:

Outgoing Mail (SMTP) Server – requires TLS: smtp.gmail.com (use authentication) Use Authentication: Yes Use STARTTLS: Yes (some clients call this SSL) Port: 465 or 587

使用phpmailer就无法正常连接gmail的发信服务器了,并且这个问题一直没有得到phpmailer的官方解决,不过在sf.net上面的讨论里倒是找到了一点资料,采用下面这种方法就可以连接gmail了。

修改class.smtp.php,第101行,把

$this->smtp_conn = fsockopen($host, # the host of the server

改成

$this->smtp_conn = fsockopen(‘ssl://’ . $host, # the host of the server

这样就可以了,就是指定使用ssl协议连接主机,当然php的openssl模块必须打开:

extension=php_openssl.dll

但是这样就不能使用非ssl的主机了,我也不像在include目录下面放两份phpmailer,于是,又琢磨出了一种更好的方式:

打开class.phpmailer.php,在大概543行附近,函数SmtpConnect()中,找到:

$this->smtp->do_debug = $this->SMTPDebug; $hosts = explode(“;”, $this->Host); $index = 0; $connection = ($this->smtp->Connected()); // Retry while there is no connection while($index < count($hosts) && $connection == false) { if(strstr($hosts[$index], ":")) list($host, $port) = explode(":", $hosts[$index]); else { $host = $hosts[$index]; $port = $this->Port; }

这一段的部分功能就是,如果你输入的主机名中带有端口号,自动的识别出来,设想虽好,但就是这部分让我们无法直接在调用的时候使用ssl格式的主机名,因为“ssl://xxx”的形式会被误认为是主机:端口号的形式,另外端口号一般都比较固定,我们手工设置好了,也不必一定要和主机一起赋值,所以在上面的代码后面添加:

//Modify by Fwolf @ 2006-4-14, to enable ssl mail connection $host = $this->Host; $port = $this->Port;

就可以了,使用正常smtp主机的时候,用法不变,使用gmail的时候,使用ssl://smtp.gmail.com作为主机名就可以了,唯一稍微麻烦一些的就是端口需要手工指定——其实也不麻烦。

按照上面的配置更改后,使用gmail账号发送邮件时还会有一条警告信息:

Warning: fgets(): SSL: fatal protocol error in H:\php_includes\phpmailer_ssl\cla ss.smtp.php on line 1024

这各警告信息在php的帮助里面有,好像是在使用ssl连接的时候,读文件读到文件尾的时候出现的问题,需要手工屏蔽,或者人为控制读的长度,我们用最简单的方式禁止警告信息显示就可以了,找到class.smtp.php的1024行,在fgets($this->smtp_conn,515)函数前面加上个@就可以了。

下面是一个完整的使用phpmailer发送邮件的函数:

function send_mail($to_address, $to_name ,$subject, $body, $attach = ”) { //使用phpmailer发送邮件 require_once(“phpmailer/class.phpmailer.php”); $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->CharSet = ‘utf-8′; $mail->Encoding = ‘base64′; $mail->From = ‘fwolf.mailagent@gmail.com’; $mail->FromName = ‘Fwolf’; //$mail->Sender = ‘fwolf.mailagent@gmail.com’; //$mail->ConfirmReadingTo = ‘fwolf.mailagent@gmail.com’; //回执? $mail->Host = ‘ssl://smtp.gmail.com’; $mail->Port = 465; //default is 25, gmail is 465 or 587 $mail->SMTPAuth = true; $mail->Username = “fwolf.mailagent@gmail.com”; $mail->Password = “xxx”; $mail->>ddAddress($to_address, $to_name); //$mail->AddReplyTo(‘fwolf.mailagent@gmail.com’, “Fwolf”); //针对gmail无用,gmail是In-Reply-To:,phpmailer默认生成的是Reply-to: $mail->WordWrap = 50; if (!empty($attach)) $mail->AddAttachment($attach); $mail->IsHTML(false); $mail->Subject = $subject; $mail->Body = $body; //$mail->AltBody = “This is the body in plain text for non-HTML mail clients”; if(!$mail->Send()) { echo “Mail send failed.\r\n”; echo “Error message: ” . $mail->ErrorInfo . “\r\n”; return false; } else { echo(“Send $attach to $to_name <$to_address> successed.\r\n”); return true; } //echo “Message has been sent”; // }

update @ 2006-11-3

感谢RainChen提供的fgets出错提示的更好解决办法(位置大概在class.smtp.php的1024行): 将:

fgets($this->smtp_conn,515)

改为:

!feof($this->smtp_conn) && $str = fgets($this->smtp_conn,515)

这样的代码就规范多了,极力不提倡使用@来屏蔽错误信息。 (未测试, 但有网友反映这种改法是不行的)

Update @ 2008-04-14

试了最新的phpMailer 2.1.0 Beta 2,不用作任何修改,就可以用gmail账号发送邮件了,官方文档中还给出了例子,和我用的方法不太一样。

不过中文附件的问题依然没有解决,需要自己hack。

Related posts

Categories: PHP Tags: , , , , ,

Gmail for ur domain暂时还无法talk

April 12th, 2006 Fwolf No comments

今天和一个朋友试了一下Gmail for ur domain,发现Gmail for ur domain的账号无法使用talk,虽然在gtalk客户端和Gmail view: standard with chat视图中都可以看到chat,也可以添加好友,但是:

一、如果添加本domain的用户,比如fwolf@xxx.com添加ksafe@xxx.com,系统会提示你对方没有gmail,而你又没有邀请额,所以无法添加,如图:

如果添加本domain的用户,比如fwolf@xxx.com添加ksafe@ xxx.com,系统会提示你对方没有gmail,而你又没有 邀请额,所以无法添加

二、如果添加其他正常的gmail用户,能够发送邀请,但对方接受之后没有反应,始终是invited状态,如图(下面那个ksafe):

如果添加其他正常的gmail用户,能够发送邀请, 但对方接受之后没有反应,始终是invited状态

经测试,添加其他正常gmail用户之后,domain用户能向对方通话(invited状态下),但对方却无法回答。

Gmail for ur domain应该说对中小企业和团队非常有用,而gtalk又是团队交流的方便工具,如果这两者不能结合使用,实在是遗憾,希望google能够尽快实现两者的互联互通哈。

Related posts

Categories: Internet Tags:

msvcrt.dll无法删除一例

April 11th, 2006 Fwolf 1 comment

一台windows2000服务器,安装了sqlserver2000,本来没事,但由于工作需要,要安装sybase 12的client,sybase 12的client是java式的安装,不仅只能在本地驱动器上执行(网络驱动器上不行),安装文件的路径中还不能包含中文,甚是麻烦。

安装的过程中提示覆盖msvcrt.dll文件,没仔细看,就给覆盖了,然后在重启的时候就发现sqlserver无法启动了,提示找不到入口。。。msvcrt.dll文件什么的,才想起来覆盖给搞坏了。

从别的地方找了一个正确的msvcrt.dll文件,想拷贝回去吧,却提示文件正在使用中,原来windows中几乎每个程序都用到了这个文件,当然无法直接覆盖了,试过了unlocker也不行,无奈,在c盘根目录新建了一个批处理文件a.bat,内容如下:

copy c:\msvcrt.dll c:\winnt\system32 /Y @rem 建一个目录,就当是成功标记了 mkdir c:\copy_ok

然后在注册表的 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce 和 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx 两个位置下新建一个字符串类型的键,内容为“c:\a.bat”,重启系统。。。。

系统重启完毕,一看copy_ok目录也建好了,但文件依然未被覆盖,再使用另外一种方式:

cd c:\winnt\system32 ren msvcrt.dll msvcrt.dll.old copy c:\msvcrt.dll .

没想到居然成功的将文件覆盖了,再次重启系统,问题解决。

不知道设置批处理那一步对后来改名的操作是否有影响,反正搞定了,收工。

Update @ 2007-04-22

今天忽然想到一个会产生这种结果的原因,那就是windows会追踪文件的更名,换一种方式解释,如果你有一个程序持续的写入一个文件,比如apache对access.log的写入,如果你在这个程序仍然运行的情况下,对文件进行更名操作,那么这个程序不会把内容写入新的文件,而是继续写入更名后的文件。所以,对msvcrt.dl进行更名并不影响它的使用,并且是系统允许的操作,而系统重启之后,一切重新开始,新文件就上岗了。

似乎Ubuntu在某些情况下也会这样,以前遇到过,程序正往一个log文件里面写东西呢,把log文件删除,期待程序生成新的log文件,而这怎么也不发生。

Related posts

Categories: Problem Tags:

[Ubuntu]安装scim输入法平台

April 7th, 2006 Fwolf No comments

fcitx安装好以后,试了一下,有些地方用着不习惯,比如输入顿号只能用\而不是/,翻页只能用-=而不能用<>,这些小地方其实对提高输入速度是很重要的,所以我现在打算把scim也安装上试试,如果自然码有linux版本的就好了。

按照www.ubuntu.org.cn上面的帮助,很轻松就把scim装上了,并且一下子就有了很多种输入法可选,我当然仍旧选择自然码咯,就是/只能输入/,而不是顿号,但是可以用<>选字,部分单字的形旁也支持,非常好,完全可以正式使用了。安装方式:

$sudo apt-get install scim scim-modules-socket scim-modules-table scim-pinyin scim-tables-zh scim-input-pad $sudo sh -c ” echo ‘export XMODIFIERS=@im=SCIM ; export GTK_IM_MODULE=”scim” ; scim -d ‘ > /etc/X11/Xsession.d/95xinput ” $sudo chmod +755 /etc/X11/Xsession.d/95xinput

其中第二句和fcitx的安装类似,就是设置一下环境参数以启用scim。

另外在这里看到scim中自然码自造词的方法,就是输入词以后,选中,然后按ctrl+a,然后输入编码回车或空格确认就可以了,在scim的状态条的那个红色的?里面其实也有说明的。遗憾的是,最多只能输入四位编码,仿佛又回到了dos时代的自然码6.0时代。

还有就是输入法选字的状态栏总是到处跑,其实windows下的firefox也存在这个问题的,但是windows下可以把它固定在屏幕底部,而在linux中怎么也不行,只能将就了。

圆体字体美化

按照如何使用圆体来美化,支持中文粗体和斜体?中的相关提示操作即可,就是那个字体文件比较大,有70多M,下载比较慢。

调整分辨率

同样参见如何调整显示的分辨率和刷新率,需要注意的是“gtf 640 480 75”中的gtf位置在“/usr/X11R6/bin/gtf”,一般路径中应该没有包含这个位置。

在vmware下配置完了以后,重启X没啥反映。但是以root身份运行一下“vmware-config-tools.pl”,中间有一个步骤问是否要重新配置分辨率,选是,自动配置完成后,重启ubuntu就生效了。

最终效果: 输入法和圆体美化都配置好了,庆祝一下~

update @ 2006-8-25 重新安装Dapper 6.06之后,64位系统下openoffic中打不开scim,32位系统中有scim就打不开openoffic,真是冤家啊,不过有解决办法:

关于scim和openoffice等软件的冲突问题,是因为scim使用了比较新的c++类库造成的,改用scim-bridge(一个用c语言编写的gtk前端模块)就可以了。 具体处理办法: sudo apt-get install scim-bridge sudo sh -c ” echo ‘export XMODIFIERS=@im=SCIM ; export GTK_IM_MODULE=”scim-bridge” ; scim -d ‘ > /etc/X11/Xsession.d/95xinput ” sudo chmod 755 -R /etc/X11/Xsession.d/95xinput

其实就是原来第二句的GTK_IM_MODULE=后面的scim变成了scim-bridge而已,来自Ubuntu中文论坛

Related posts

Categories: Linux Tags:

Install Chinese Input Method on Ubuntu

April 6th, 2006 Fwolf 1 comment

Only english in this document because I can only input english now …

fcitx

Download fcitx-3.1.1.tar.bz2 from http://www.fcitx.org/.

tar xjf fcitx-3.1.1.tar.bz2 cd fcitx-3.1.1 ./configure

But I got error message below:

root@ubuntu:/home/fwolf/download/fcitx-3.1.1# ./configure checking for a BSD-compatible install… /usr/bin/install -c checking whether build environment is sane… yes checking for gawk… no checking for mawk… mawk checking whether make sets $(MAKE)… yes checking build system type… i686-pc-linux-gnulibc1 checking host system type… i686-pc-linux-gnulibc1 checking for gcc… gcc checking for C compiler default output file name… configure: error: C compiler cannot create executables See `config.log’ for more details.

The answer is here, and I need crt1.o, which is in libc6-dev

usr/lib/crt1.o libdevel/libc6-dev

ps: how to find where crtl.o is ?

Install libc6-dev using apt-get, and run ./configure successful, then make, but fail:

root@ubuntu:/home/fwolf/download/fcitx-3.1.1# make make all-recursive make[1]: Entering directory `/home/fwolf/download/fcitx-3.1.1′ Making all in doc make[2]: Entering directory `/home/fwolf/download/fcitx-3.1.1/doc’ make[2]: Nothing to be done for `all’. make[2]: Leaving directory `/home/fwolf/download/fcitx-3.1.1/doc’ Making all in tools make[2]: Entering directory `/home/fwolf/download/fcitx-3.1.1/tools’ gcc -g -O2 -INONE -Wall -o mb2txt mb2txt.o -LNONE -lX11 /usr/bin/ld: cannot find -lX11 collect2: ld returned 1 exit status make[2]: *** [mb2txt] Error 1 make[2]: Leaving directory `/home/fwolf/download/fcitx-3.1.1/tools’ make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/fwolf/download/fcitx-3.1.1′ make: *** [all] Error 2

Seems “cannot find -lX11″, so install libx11-dev, make again, error again :

… /home/fwolf/download/fcitx-3.1.1/tools/txt2mb.c:115: undefined reference to `rpl_malloc’ txt2mb.o:/home/fwolf/download/fcitx-3.1.1/tools/txt2mb.c:121: more undefined references to `rpl_malloc’ follow collect2: ld returned 1 exit status …

Comment “#define malloc rpl_malloc” in config.h, then make again, done. About this error, see also here and here.

Command “make install” successful executed, run command “make clean” to remove binaries and object file wile make, and “make distclean” to also remove file created by ./configure.

Then run this two command config fcitx to Xwindows:

sh -c ” echo ‘export XMODIFIERS=@im=fcitx ; export GTK_IM_MODULE=”fcitx” ; fcitx ‘ > /etc/X11/Xsession.d/95xinput ” chmod +755 /etc/X11/Xsession.d/95xinput

Rebooting……Ubuntu or Xwindows, when restarting, I found there is a ime bar, but dispear when Xwindows completely loaded, and ‘ctrl+space’ don’t functional, run fcitx under bash, found error:

fwolf@ubuntu:~/download/fcitx-3.1.1$ fcitx Error: Cannot Create Chinese Fonts: -*-*-medium-r-normal–14-*-*-*-*-*-*-*,-*-Courier-medium-r-normal–14-*-*-*-*-*-*-* Using Default … Error: Cannot Create Chinese Fonts! Error: Cannot Create Chinese Fonts: -*-*-medium-r-normal–16-*-*-*-*-*-*-*,-*-Courier-medium-r-normal–16-*-*-*-*-*-*-* Using Default … Error: Cannot Create Chinese Fonts! Start FCITX error. Another XIM daemon named fcitx is running?

It need chinese fonts, my ubuntu is a english version, seems i need add chinese font support. Command ‘apt-get install ttf-arphic-ukai ttf-arphic-uming’ on ubuntu.org.cn does’nt work, in my ubuntu, chinese font seems to be:

i ttf-arphic-gbsn00lp – “AR PL SungtiL GB” Chinese TrueType font i ttf-arphic-gkai00mp – “AR PL KaitiM GB” Chinese TrueType font b

so: ‘apt-get install ttf-arphic-gbsn00lp ttf-arphic-gkai00mp’ (aptitude search ttf is a good command), but they are all newest version already, so I have to run ‘apt-get install language-pack-gnome-zh language-pack-gnome-zh-base language-pack-zh language-pack-zh-base language-support-zh’ to install whole zh language pack.

After long time download and waiting, language-pack is installed.

Selecting previously deselected package language-support-zh. Unpacking language-support-zh (from …/language-support-zh_20051010_all.deb) … Setting up mozilla-firefox-locale-zh-tw (1.0.4lang20050515-1ubuntu3) … Updating mozilla-firefox chrome registry…done. Setting up openoffice.org2-l10n-zh-cn (1.9.129-0.1ubuntu3) … Setting up openoffice.org2-l10n-zh-tw (1.9.129-0.1ubuntu3) … Setting up openoffice.org2-help-zh-cn (1.9.129-0.1ubuntu5) … Setting up openoffice.org2-help-zh-tw (1.9.129-0.1ubuntu5) … Setting up mozilla-firefox-locale-zh-cn (1.0.4lang20050515-1ubuntu3) … Updating mozilla-firefox chrome registry…done. Setting up language-support-zh (20051010) … Setting up language-pack-zh (20060126) … Setting up language-pack-zh-base (20051011) … Generating locales… zh_CN.UTF-8… done zh_HK.UTF-8… done zh_TW.UTF-8… done Generation complete. Setting up language-pack-gnome-zh (20060126) … Setting up language-pack-gnome-zh-base (20051011) …

But still not working, hmm… search using Google… and find this, so add below:

# enable chinese input method export LC_ALL=zh_CN.UTF-8 export LANG==zh_CN.UTF-8 export XMODIFIERS=@im=fcitx

in .bashrc, so locale changed tu zh_CN.UTF-8, but still “Error: Cannot Create Chinese Fonts!”, so problem is on my chinese font or setting.

fwolf@ubuntu:~$ xlsfonts | grep zh_CN fwolf@ubuntu:~$

I have not install chinese font yet ? I followed this document and run ” sudo gedit /etc/environment”, change it’s content to:

LANGUAGE=”en_US:en” LC_CTYPE=zh_CN.UTF-8 LANG=en_US.UTF-8 GST_ID3_TAG_ENCODING=GBK

(Because I’m english interface)

Restart Xwindows again, My fcitx input bar appeared!!! But can input chinese “invisiblely” , like this picture:

My fcitx input bar appeared!!! But can input chinese 'invisiblely'

It still cannot find chinese font file…so find my chinese font file:

fwolf@ubuntu:~$ xlsfonts | grep gb … -default-song-medium-r-normal–0-0-72-72-m-0-gb2312.1980-0 …

Then edit ~/.fcitx/config(use gedit), if this file cannot display chinese currectly, set ENV to zh_CN.UTF-8 using command “export LANG=zh_CN.UTF-8″, change “显示字体(中)=*” at line 2 to “显示字体(中)=song”, not work. here said fcitx need gbk font, but system have only gb2312 font, need and how do I install gbk font ?

终于搞定了,就是字体设置的问题,但不是需要安装什么字体,而是需要执行”dpkg-reconfigure locales”,然后把zh_CN.GB2312也选择上就可以了,所以说fcitx需要的不是什么gbk字体,而是gb2312字体,网上有些说的和我遇到的实际情况不一样。

估计修改”~/.fcitx/config”文件中的zh_CN.GB2312,改成gbk、utf8什么的应该也可以,但我在前面设置没有成功。

装个中文输入法几乎用去两天时间,翻阅网站无数,太累了,scim的安装和中文美化就在下一篇再写吧。

Related posts

Categories: Linux Tags: