Martin Muggli
Martin Muggli

Reputation: 13

Zend framework 1 Zend_Mail setFrom name will shortened or deleted

hi i will send a normal email with zend mail via smtp. It works fine. But the 'from' must but the fromemail should look like this :

$mail->setFrom('[email protected]', '[email protected]');

my goal is to have something like that in the email programm:

"[email protected]" <[email protected]> 

but I only see this:

 <[email protected]> 

or something like that

"[email protected]" <[email protected]> 

result:

"firtstudio@" <[email protected]> 

I need the full name. how?

Upvotes: 1

Views: 526

Answers (2)

Joel Lord
Joel Lord

Reputation: 2173

If you look at Zend_Mail, the setFrom uses an internal function named _formatAddress to set the display name. The function goes as follows:

/**
     * Formats e-mail address
     *
     * @param string $email
     * @param string $name
     * @return string
     */
    protected function _formatAddress($email, $name)
    {
        if ($name === '' || $name === null || $name === $email) {
            return $email;
        } else {
            $encodedName = $this->_encodeHeader($name);
            if ($encodedName === $name  &&  strcspn($name, '()<>[]:;@\\,') != strlen($name)) {
                $format = '"%s" <%s>';
            } else {
                $format = '%s <%s>';
            }
            return sprintf($format, $encodedName, $email);
        }
    }

As you can see, if the email and name are the same, the function will only return the email. Here are some things you could try to display it:

$mailer->setFrom('[email protected]', 'Firt Studio');

would display it as Firt Studio

or you could edit the _formatAddress function in the Zend_Mailer library to remove the

 || $name === $email

condition and you would get

[email protected] <[email protected]>

Upvotes: 1

Orangepill
Orangepill

Reputation: 24645

Zend Mail does not write out the name if it is Identical to the email address (see Zend_Mail::_formatAddress).

The name property (second parameter) is intended to be a Common name to the email address.

Upvotes: 0

Related Questions