Bug #18701 » 8255_alt_v1.diff
t3lib/class.t3lib_htmlmail.php (working copy) | ||
---|---|---|
// From
|
||
if ($this->from_email) {
|
||
if ($this->from_name) {
|
||
if ($this->from_name && !t3lib_div::isBrokenEmailEnv()) {
|
||
$this->add_header('From: '.$this->from_name.' <'.$this->from_email.'>');
|
||
} else {
|
||
$this->add_header('From: '.$this->from_email);
|
||
... | ... | |
// On windows the -f flag is not used (specific for Sendmail and Postfix),
|
||
// but instead the php.ini parameter sendmail_from is used.
|
||
$returnPath = (strlen($this->returnPath) > 0) ? '-f'.$this->returnPath : '';
|
||
$returnPath = (strlen($this->returnPath) > 0) ? '-f "' . addslashes($this->returnPath) . '"' : '';
|
||
if($this->returnPath) {
|
||
ini_set(sendmail_from, $this->returnPath);
|
||
ini_set('sendmail_from', t3lib_div::adjustMailAddressForEnv($this->returnPath));
|
||
}
|
||
$recipient = t3lib_div::adjustMailAddressForEnv($this->recipient);
|
||
$recipient_copy = t3lib_div::adjustMailAddressForEnv($this->recipient_copy);
|
||
// If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On
|
||
$returnPathPossible = (!ini_get('safe_mode') && $this->forceReturnPath);
|
||
if ($returnPathPossible) {
|
||
$mailWasSent = mail($this->recipient,
|
||
$mailWasSent = mail($recipient,
|
||
$this->subject,
|
||
$this->message,
|
||
$this->headers,
|
||
$returnPath);
|
||
} else {
|
||
$mailWasSent = mail($this->recipient,
|
||
$mailWasSent = mail($recipient,
|
||
$this->subject,
|
||
$this->message,
|
||
$this->headers);
|
||
}
|
||
// Sending a copy
|
||
if ($this->recipient_copy) {
|
||
if ($recipient_copy) {
|
||
if ($returnPathPossible) {
|
||
$mailWasSent = mail($this->recipient_copy,
|
||
$mailWasSent = mail($recipient_copy,
|
||
$this->subject,
|
||
$this->message,
|
||
$this->headers,
|
||
$returnPath);
|
||
} else {
|
||
$mailWasSent = mail($this->recipient_copy,
|
||
$mailWasSent = mail($recipient_copy,
|
||
$this->subject,
|
||
$this->message,
|
||
$this->headers);
|
||
... | ... | |
$mailWasSent = mail($this->from_email,
|
||
$theParts[0],
|
||
$theParts[1],
|
||
"From: ".$this->recipient,
|
||
'From: ' . $recipient,
|
||
$returnPath);
|
||
} else {
|
||
$mailWasSent = mail($this->from_email,
|
||
$theParts[0],
|
||
$theParts[1],
|
||
"From: ".$this->recipient);
|
||
'From: ' . $recipient);
|
||
}
|
||
}
|
||
if ($this->returnPath) {
|
||
ini_restore(sendmail_from);
|
||
ini_restore('sendmail_from');
|
||
}
|
||
return $mailWasSent;
|
||
}
|
t3lib/class.t3lib_div.php (working copy) | ||
---|---|---|
}
|
||
/**
|
||
* Checks if current e-mail sending method does not accept recipient/sender name
|
||
* in a call to PHP mail() function. Windows version of mail() and mini_sendmail
|
||
* program are known not to process such input correctly and they cause SMTP
|
||
* errors. This function will return true if current mail sending method has
|
||
* problem with recipient name in recipient/sender argument for mail().
|
||
*
|
||
* TODO: 4.3 should have additional configuration variable, which is combined
|
||
* by || with the rest in this function.
|
||
*
|
||
* @return boolean true if mail() does not accept recipient name
|
||
*/
|
||
public static function isBrokenEmailEnv() {
|
||
return TYPO3_OS == 'WIN' || (false !== strpos(ini_get('sendmail_path'), 'mini_sendmail'));
|
||
}
|
||
/**
|
||
* Changes from/to arguments for mail() function to work in any environment.
|
||
*
|
||
* @param string $address Address to adjust
|
||
* @return string Adjusted address
|
||
* @see t3lib_::isBrokenEmailEnv()
|
||
*/
|
||
public static function adjustMailAddressForEnv($address) {
|
||
if (self::isBrokenEmailEnv() && false !== ($pos1 = strrpos($address, '<'))) {
|
||
$pos2 = strpos($address, '>', $pos1);
|
||
$address = substr($address, $pos1 + 1, ($pos2 ? $pos2 : strlen($address)) - $pos1 - 1);
|
||
}
|
||
return $address;
|
||
}
|
||
/**
|
||
* Formats a string for output between <textarea>-tags
|
||
* All content outputted in a textarea form should be passed through this function
|
||
* Not only is the content htmlspecialchar'ed on output but there is also a single newline added in the top. The newline is necessary because browsers will ignore the first newline after <textarea> if that is the first character. Therefore better set it!
|
||
... | ... | |
$charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'ISO-8859-1';
|
||
}
|
||
$email = self::adjustMailAddressForEnv($email);
|
||
if (!$dontEncodeHeader) {
|
||
// Mail headers must be ASCII, therefore we convert the whole header to either base64 or quoted_printable
|
||
$newHeaders=array();
|
||
foreach (explode(chr(10),$headers) as $line) { // Split the header in lines and convert each line separately
|
||
$parts = explode(': ',$line,2); // Field tags must not be encoded
|
||
if (count($parts)==2) {
|
||
if (0 == strcasecmp($parts[0], 'from')) {
|
||
$parts[1] = self::adjustMailAddressForEnv($parts[1]);
|
||
}
|
||
$parts[1] = t3lib_div::encodeHeader($parts[1],$encoding,$charset);
|
||
$newHeaders[] = implode(': ',$parts);
|
||
} else {
|
||
... | ... | |
break;
|
||
}
|
||
$linebreak = chr(10); // Default line break for Unix systems.
|
||
if (TYPO3_OS=='WIN') {
|
||
$linebreak = chr(13).chr(10); // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the linebreak needs to be \r\n.
|
||
}
|
||
// Headers must be separated by CRLF according to RFC 2822, not just LF.
|
||
// But many servers (Gmail, for example) behave incorectly and want only LF.
|
||
// So we stick to LF in all cases.
|
||
$headers = trim(implode(chr(10), t3lib_div::trimExplode(chr(10), $headers, true))); // Make sure no empty lines are there.
|
||
$headers=trim(implode($linebreak,t3lib_div::trimExplode(chr(10),$headers,1))); // Make sure no empty lines are there.
|
||
$ret = @mail($email,$subject,$message,$headers);
|
||
$ret = @mail($email, $subject, $message, $headers);
|
||
if (!$ret) {
|
||
t3lib_div::sysLog('Mail to "'.$email.'" could not be sent (Subject: "'.$subject.'").', 'Core', 3);
|
||
}
|