Browse files

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

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

Fixes #2910
  • Loading branch information...
1 parent e89081a commit 549908738b9259484f4c90f347a8020a3d4e2063 @markstory markstory committed Mar 2, 2014
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/Cake/Network/Email/MailTransport.php
View
8 lib/Cake/Network/Email/MailTransport.php
@@ -67,11 +67,15 @@ protected function _mail($to, $subject, $message, $headers, $params = null) {
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);
}
}

0 comments on commit 5499087

Please sign in to comment.