Browse Source

Include the last error if available when sending with mail() fails.

When sending email using mail() include the last error if available.

Fixes #2910
mark_story 12 years ago
parent
commit
549908738b
1 changed files with 6 additions and 2 deletions
  1. 6 2
      lib/Cake/Network/Email/MailTransport.php

+ 6 - 2
lib/Cake/Network/Email/MailTransport.php

@@ -67,11 +67,15 @@ class MailTransport extends AbstractTransport {
 		if (ini_get('safe_mode')) {
 			//@codingStandardsIgnoreStart
 			if (!@mail($to, $subject, $message, $headers)) {
-				throw new SocketException(__d('cake_dev', 'Could not send email.'));
+				$error = error_get_last();
+				$msg = 'Could not send email: ' . isset($error['message']) ? $error['message'] : 'unknown';
+				throw new SocketException($msg);
 			}
 		} elseif (!@mail($to, $subject, $message, $headers, $params)) {
+			$error = error_get_last();
+			$msg = 'Could not send email: ' . isset($error['message']) ? $error['message'] : 'unknown';
 			//@codingStandardsIgnoreEnd
-			throw new SocketException(__d('cake_dev', 'Could not send email.'));
+			throw new SocketException($msg);
 		}
 	}