[wp-trac] [WordPress Trac] #19847: wp_mail $from_name field is removing an extra character from the name

WordPress Trac wp-trac at lists.automattic.com
Wed Jan 18 09:15:12 UTC 2012


#19847: wp_mail $from_name field is removing an extra character from the name
--------------------------+------------------------------
 Reporter:  hakanca       |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  3.3.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------------------
Changes (by hakanca):

 * keywords:  has-patch reporter-feedback => has-patch


Comment:

 It doesn't really matter if we have a space there or not. '''strpos'''
 returns the numeric position of the found string; in our case "<"
 character. '''substr''' returns as many characters specified by its length
 parameter; in our case the number we get from '''strpos'''. Both functions
 start counting from "0" unless we specify otherwise; which is our case. So
 in the following cases:

 Hakan<hakan@…> --> strpos will return 5; the index position of "<" in the
 original string starting from "0". So substr will return "Hakan" since we
 are returning 5 characters from the beginning.

 If, as you asked, we have a space between the name and email like below:

 Hakan <hakan@…> --> then strpos will return 6, and substr will also
 include 6 characters and return "Hakan " -including the space-. Since we
 are already trimming the space in the returned string 2 lines later in the
 code with
 {{{
 $from_name = trim( $from_name );
 }}}
 There is no need to subtract 1 from the length of the string, since we
 never run into problem of accidentally including that "<" character. '''I
 think that was the false logic behind adding that -1 to substr call in the
 first place.
 '''
 By removing that "-1" we are actually making the code more flexible, by
 accommodating both versions. (i.e. with or without space) And to the best
 of my knowledge, PHP has no problem sending the email in either
 case.(Tested on my server)

 As for making patches to the Wordpress core, I am not an expert PHP coder
 per se. I'd rather leave it to people who know what they are doing. :)

 ----

 Replying to [comment:1 kawauso]:
 > Are you passing in the From value without a space?
 >
 > i.e. Hakan<hakan at somemail.com>
 >
 > If not, can you provide an example to reproduce?
 >
 > Also, please see patching for
 [http://markjaquith.wordpress.com/2005/11/02/my-wordpress-toolbox/
 Windows] and [http://blog.ftwr.co.uk/archives/2005/11/03/windows-
 wordpress-toolbox/ *nix]

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19847#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list