Forum Moderators: coopster

Message Too Old, No Replies

strange behavior of mail() function

strange (base64) code is sent instead of html email

         

phparion

7:14 am on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

On one of our Servers I am facing strange problem with mail(). Sometimes I get correct HTML email and sometimes it sends strange code e.g below,

begin 666 student registration alert.htm
M4F5V:65W960@1&%T93H@,C P."TP-"TR,B!2979I97=D($)Y.B!'96]R9V4\
M8G(^16UA:6PZ(&=K97!N:6-K0&=M86EL+F-O;2 \8G(^/&$@:')E9CTB:'1T
M<#HO+W=S+F%R:6XN;F5T+W=H;VES+S]Q=65R>6EN<'5T/38W+C,V+C$X,RXS
M,2(^5TA/25,H=7-E<B!)4"D\+V$^(#QB<CY4:71L93H@22!H879E(&)E96X@
M:&%P<&EL>2!U<VEN9R!.971F(%L@/&$@:')E9CTB:'1T<#HO+W=W=RYM;W9I
M97-I;FAO=7-E+F-O;2]C;VYT<F]L<F]O;2]V:7-I=&]R7W)E=FEE=W-?;6%N
M86=E<BYP:' _=E]R979?:60],B9S:&]W7V9O<FT],2(^07!P<F]V92]$96-L
M:6YE/"]A/B!=/&)R/D9O<CH@/&$@:')E9CTB:'1T<#HO+W=W=RYM;W9I97-I
M;FAO=7-E+F-O;2]R979I97=S+VYE=&9L:7@N:'1M;"(^3F5T9FQI>#PO83X@
M/&)R/BTM+2TM+2TM+2TM+2TM+2TM+2TM+2HJ($5.1" J*BTM+2TM+2TM+2TM
M+2TM+2TM+2TM+2 \8G(^/&)R/E)E=FEE=V5D($1A=&4Z(#(P,#@M,#0M,C(@
M4F5V:65W9"!">3H@1V5O<F=E/&)R/D5M86EL.B!G:V5P;FEC:T!G;6%I;"YC
M;VT@/&)R/CQA(&AR968](FAT=' Z+R]W<RYA<FEN+FYE="]W:&]I<R\_<75E
M<GEI;G!U=#TV-RXS-BXQ.#,N,S$B/E=(3TE3*'5S97(@25 I/"]A/B \8G(^
M5&ET;&4Z($D@=7-E9"!";&]C:V)U<W1E<B!F;W(@;VYL>2!A("!;(#QA(&AR
M968](FAT=' Z+R]W=W<N;6]V:65S:6YH;W5S92YC;VTO8V]N=')O;')O;VTO
M=FES:71O<E]R979I97=S7VUA;F%G97(N<&AP/W9?<F5V7VED/3,F<VAO=U]F
M;W)M/3$B/D%P<')O=F4O1&5C;&EN93PO83X@73QB<CY&;W(Z(#QA(&AR968]
M(FAT=' Z+R]W=W<N;6]V:65S:6YH;W5S92YC;VTO<F5V:65W<R]B;&]C:V)U
M<W1E<BYH=&UL(CY";&]C:V)U<W1E<CPO83X@/&)R/BTM+2TM+2TM+2TM+2TM
M+2TM+2TM+2HJ($5.1" J*BTM+2TM+2TM+2TM+2TM+2TM+2TM+2 \8G(^/&)R
#/@T*
`
end

Now while I am writing this post, it has started to work fine again and sending correct html emails. I am terribly disturbed by this behavior of emails. Can anybody guide me please what is happening on my this server?

thank you

[edited by: eelixduppy at 11:05 am (utc) on May 5, 2008]
[edit reason] disabled smileys [/edit]

Otaku

10:27 am on May 5, 2008 (gmt 0)

10+ Year Member



If you change nothing and the behavior is changing, maybe there are some settings, PHP or sendmail, related to message encoding(s) set to 'auto' or something... and that mechanism sometimes decides, based on the attachment contents, that it should encode it differently... and you gotta find it and change to some constant value, like base64.

penders

11:33 am on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sometimes I get correct HTML email and sometimes it sends strange code...

I think that strange 'code' is your email encoded as base64 - a common encoding for emails and attachments. If the correct headers are present I would have thought the email client would convert it back?

For instance, if you convert your 'code' back, part of the email includes... "Title: I used Blockbuster for only a"

phparion

1:34 pm on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



how did you convert it back? lol

here is my mail()

mail("me@example.com","subject",$body,"From:no-reply@example.com\r\ncontent-type:text/html");

and exim has been setup on our server.

phparion

1:44 pm on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



mail("me@example.com","subject",$body,"From:no-reply@example.com\r\ncontent-type:text/html;charset=iso-8859-1");

the above worked, thank you. I found an online tool for converting back base64, however not sure if php has some built in functions for it.. please add to my knowledge about it. thank you

penders

2:25 pm on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I found an online tool for converting back base64, however not sure if php has some built in functions for it..

I used an online tool as well, but yes, PHP does have base64_decode() [uk.php.net] which should do the job.