I’ve been looking for guides on how to read and understand a stack trace.
In this case, people are getting errors when trying to fill out and send an contact form. And I’am really having trouble fixing this, and it’s not any easier when I cannot decipher the stack. (This is a magento 1.6.2 installation)
The email are being sent, but the contact form tells the user that there was a problem, so we get alot of duplicates from people trying again, and again.
exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail. mail(/var/www/site.dk/logs/php-maillog.log): failed to open stream: Permission denied' in /var/www/site.dk/public_html/lib/Zend/Mail/Transport/Sendmail.php:137
Stack trace:
#0 /var/www/site.dk/public_html/lib/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Sendmail->_sendMail()
#1 /var/www/site.dk/public_html/lib/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#2 /var/www/site.dk/public_html/app/code/core/Mage/Core/Model/Email/Template.php(409): Zend_Mail->send()
#3 /var/www/site.dk/public_html/app/code/core/Mage/Core/Model/Email/Template.php(462): Mage_Core_Model_Email_Template->send('email@email.com', NULL, Array)
#4 /var/www/site.dk/public_html/app/code/core/Mage/Contacts/controllers/IndexController.php(104): Mage_Core_Model_Email_Template->sendTransactional('1', 'general', 'email@email.com', NULL, Array)
#5 /var/www/site.dk/public_html/app/code/local/Mage/Core/Controller/Varien/Action.php(420): Mage_Contacts_IndexController->postAction()
#6 /var/www/site.dk/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('post')
#7 /var/www/site.dk/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /var/www/site.dk/public_html/app/code/local/Mage/Core/Model/App.php(348): Mage_Core_Controller_Varien_Front->dispatch()
#9 /var/www/site.dk/public_html/app/Mage.php(640): Mage_Core_Model_App->run(Array)
#10 /var/www/site.dk/public_html/shop/index.php(80): Mage::run('store...', 'store')
#11 {main}
The snippet from sendmail.php
public function _sendMail()
{
if ($this->parameters === null) {
set_error_handler(array($this, '_handleMailErrors'));
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header);
restore_error_handler();
} else {
if(!is_string($this->parameters)) {
/**
* @see Zend_Mail_Transport_Exception
*
* Exception is thrown here because
* $parameters is a public property
*/
#require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception(
'Parameters were set but are not a string'
);
}
set_error_handler(array($this, '_handleMailErrors'));
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header,
$this->parameters);
restore_error_handler();
}
if ($this->_errstr !== null || !$result) {
/**
* @see Zend_Mail_Transport_Exception
*/
#require_once 'Zend/Mail/Transport/Exception.php';
(137) throw new Zend_Mail_Transport_Exception('Unable to send mail. ' . $this->_errstr);
}
}
I was going to write this as a comment, but it’s going to be too long for the comment box.
If we go through the stack trace line by line you will start to understand what’s going on:
Firstly, the exception type, it’s
Zend_Mail_Transport_Exceptionwhich will give us an idea on where to start looking. In this case it’s an error occurring somewhere in the Zend_Mail code.Secondly, the message
'Unable to send mail. mail(/var/www/site.dk/logs/php-maillog.log): failed to open stream: Permission denied'. To me, this seems pretty clear, we are getting a permission denied error when the php-maillog.log is trying to be opened. What’s causing this? That’s what you will have to determine.Thirdly, we are shown where the exception is actually occurring
/var/www/site.dk/public_html/lib/Zend/Mail/Transport/Sendmail.php:137. So it’s occurring on line 137 of the Sendmail.php as you have noted.The rest of the stack trace is the path that PHP took to get to the error. That is, which function called what to get to the point where you are seeing the exception. This is reported from the last thing to be added onto the stack, back to the first, so you are pretty much tracing your code backwards through the function calls.
In this case, you can see that the code on line 348 of
/var/www/site.dk/public_html/lib/Zend/Mail/Transport/Abstract.phpcalled the _sendMail function which exceptioned…the line 348 code was called by the code on line 1194 in/var/www/site.dk/public_html/lib/Zend/Mail.phpand so on.TL:DR?
Magento is having an issue opening the
/var/www/site.dk/logs/php-maillog.logfile. Are the permissions set correctly for this file? Does the/var/www/site.dk/logs/directory exist?