Question

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('firt-studio@example-test.com', 'firt-studio@example-test.com');

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

"firt-studio@example-test.com" <firt-studio@example-test.com> 

but I only see this:

 <firt-studio@example-test.com> 

or something like that

"firtstudio@example-test.com" <firt-studio@example-test.com> 

result:

"firtstudio@" <firt-studio@example-test.com> 

I need the full name. how?

Was it helpful?

Solution

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('firt-studio@example-test.com', '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

firt-studio@example-test.com <firt-studio@example-test.com>

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top