About the solution to the problem of garbled Chinese attachment names when using sendmail to send mail in PHP

Problem description: The Chinese attachment name appears garbled when sending mail in php using sendmail, as shown in the figure:
Original name: Afeng.jpg

Reason analysis: This is an error caused by coding.
Solution: First force the encoding change:
substr($file_name,strrpos($file_name,'/') +1 )
where $file_name is the file path.
Then convert the encoding to Chinese encoding GB2312 format:

mb_convert_encoding(substr($file_name,strrpos($file_name,'/') +1 ),"GB2312")

Get it done! The results are as follows:
successful

PS: basename() cannot parse Chinese, directly filter out Chinese information and turn it into .jpg

Conclusion: The first step above is from https://blog.csdn.net/kongbu0622/article/details/7313742
must thank you! The second step is original, reprint freely, hope to help you!

Guess you like

Origin blog.csdn.net/qq_40266867/article/details/81568524