function mimemail_address in Mime Mail 5
Same name and namespace in other branches
- 6 mimemail.inc \mimemail_address()
- 7 mimemail.inc \mimemail_address()
Formats an address string. TODO could use some enhancement and stress testing.
Parameters
$address: A user object, a text email address or an array containing name, mail.
Return value
A formatted address string or FALSE.
1 call to mimemail_address()
- mimemail_prepare in ./
mimemail.module - Sends a mime-encoded e-mail.
File
- ./
mimemail.module, line 419 - Component module for sending Mime-encoded emails.
Code
function mimemail_address($address) {
if (is_array($address)) {
// it's an array containing 'mail' and/or 'name'
if (isset($address['mail'])) {
$output = '';
if (empty($address['name'])) {
return $address['mail'];
}
else {
return '"' . addslashes(mime_header_encode($address['name'])) . '" <' . $address['mail'] . '>';
}
}
// it's an array of address items
$addresses = array();
foreach ($address as $a) {
$addresses[] = mimemail_address($a);
}
return $addresses;
}
// it's a user object
if (is_object($address) && isset($address->mail)) {
return '"' . addslashes(mime_header_encode($address->name)) . '" <' . $address->mail . '>';
}
// it's formatted or unformatted string
// TODO shouldn't assume it's valid - should try to re-parse
if (is_string($address)) {
return $address;
}
// it's null. return the site default address
if (is_null($address)) {
return array(
'name' => mime_header_encode(variable_get('site_name', 'Drupal')),
'mail' => variable_get('site_mail', ini_get('sendmail_from')),
);
}
return FALSE;
}