php-simple-mail
php-simple-mail copied to clipboard
mail(): Policy restriction in effect. The fifth parameter is disabled on this system.
// PHP mail() statement
mail(
$to,
$subject,
$message,
$additional_headers = [],
$additional_params = ""
)
My hosting provider has activated some policy, that the Php mail() function must not be called with 5 parameters. Effectively disallowing $additional_params. When providing a 5th parameter a Php warning mail(): Policy restriction in effect. The fifth parameter is disabled on this system. is issued.
The function send() uses the mail() statement.
// OLD
public function send()
{
$to = $this->getToForSend();
$headers = $this->getHeadersForSend();
if (empty($to)) {
throw new \RuntimeException(
'Unable to send, no To address has been set.'
);
}
if ($this->hasAttachments()) {
$message = $this->assembleAttachmentBody();
$headers .= PHP_EOL . $this->assembleAttachmentHeaders();
} else {
$message = $this->getWrapMessage();
}
return mail($to, $this->_subject, $message, $headers, $this->_params);
}
Changing this to below solves the warning.
// CHANGED
public function send()
{
$to = $this->getToForSend();
$headers = $this->getHeadersForSend();
if (empty($to)) {
throw new \RuntimeException(
'Unable to send, no To address has been set.'
);
}
if ($this->hasAttachments()) {
$message = $this->assembleAttachmentBody();
$headers .= PHP_EOL . $this->assembleAttachmentHeaders();
} else {
$message = $this->getWrapMessage();
}
if ($this->_params !== null) {
return mail($to, $this->_subject, $message, $headers, $this->_params);
} else {
return mail($to, $this->_subject, $message, $headers);
}
}
P.S. Sorry, I am unable to provide a PR.