Index: t3lib/class.t3lib_htmlmail.php
===================================================================
--- t3lib/class.t3lib_htmlmail.php (revision 3639)
+++ t3lib/class.t3lib_htmlmail.php (working copy)
@@ -476,7 +476,7 @@
// 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);
@@ -708,35 +708,38 @@
// 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);
@@ -750,17 +753,17 @@
$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;
}
Index: t3lib/class.t3lib_div.php
===================================================================
--- t3lib/class.t3lib_div.php (revision 3639)
+++ t3lib/class.t3lib_div.php (working copy)
@@ -1427,6 +1427,37 @@
}
/**
+ * 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