function swiftmailer_add_parameterized_header in Swift Mailer 7
Adds a parameterized header to a message.
Parameters
Swift_Message $message: The message which the parameterized header is to be added to.
string $key: The header key.
string $value: The header value.
1 call to swiftmailer_add_parameterized_header()
- SWIFTMailSystem::mail in includes/
classes/ SWIFTMailSystem.inc - Sends a message composed by drupal_mail().
File
- includes/
helpers/ conversion.inc, line 100 - This file contains conversion functions.
Code
function swiftmailer_add_parameterized_header(Swift_Message $message, $key, $value) {
// Remove any already existing header identified by the provided key.
swiftmailer_remove_header($message, $key);
// Define variables to hold the header's value and parameters.
$header_value = NULL;
$header_parameters = array();
// Split the provided value by ';' (semicolon), which we assume is the
// character is used to separate the parameters.
$parameter_pairs = explode(';', $value);
// Iterate through the extracted parameters, and prepare each of them to be
// added to a parameterized message header. There should be a single text
// parameter and one or more key/value parameters in the provided header
// value. We assume that a '=' (equals) character is used to separate the
// key and value for each of the parameters.
foreach ($parameter_pairs as $parameter_pair) {
// Find out whether the current parameter pair really is a parameter
// pair or just a single value.
if (preg_match('/=/', $parameter_pair) > 0) {
// Split the parameter so that we can access the parameter's key and
// value separately.
$parameter_pair = explode('=', $parameter_pair);
// Validate that the parameter has been split in two, and that both
// the parameter's key and value is accessible. If that is the case,
// then add the current parameter's key and value to the array which
// holds all parameters to be added to the current header.
if (!empty($parameter_pair[0]) && !empty($parameter_pair[1])) {
$header_parameters[trim($parameter_pair[0])] = trim($parameter_pair[1]);
}
}
else {
$header_value = trim($parameter_pair);
}
}
// Add the parameterized header.
$message
->getHeaders()
->addParameterizedHeader($key, $header_value, $header_parameters);
}