Laravel 5.2 + mono log critical error send to mail - email

How I can send every critical error exception to email. in current Laravel 5.2 it log in /storage/logs/laravel.log file. I want get that critical error in to mail with MailHandler but don't know how to implement it.
in file we get this type of error :
[2017-12-07 09:32:51] local.ERROR: ParseError: syntax error, unexpected 'if' (T_IF) in /home/ilogix/Workspace/cudefender/site/app/Http/Controllers/FormsController.php:53
Stack trace:
#0 /home/ilogix/Workspace/cudefender/site/vendor/composer/ClassLoader.php(301): Composer\Autoload\includeFile('/home/ilogix/Wo...')
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass('App\\Http\\Contro...')
#2 [internal function]: spl_autoload_call('App\\Http\\Contro...')
#3 /home/ilogix/Workspace/cudefender/site/vendor/laravel/framework/src/Illuminate/Routing/Route.php(280): ReflectionMethod->__construct('App\\Http\\Contro...', 'index')
i need same in email by monolog mail handler.

You can edit the app/Exceptions/Handler.php file to send emails to a given address. For example, edit the report function to:
public function report(Exception $e)
{
try {
\Mail::raw( $e->__toString(), function ( $m ) {
$m->from('no-reply#your-app.com', 'APP_NAME');
$m->to( 'name#domain.com' )->subject('APP_NAME - Fatal Error' );
});
} catch ( \Exception $e ) {
// ignore
}
parent::report($e);
}
This code will send the contents of the Exception $e to name#domain.com. You can change the from address, and subject to be anything you want.
Depending on the error encountered, the message you receive would look like:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException in
your-app/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:161
Stack trace: #0
your-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(821):
Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
...

Related

Regarding SSL Protocol in SMTP server Validity

I've success to sent a mail through PHP in last month with this code.
if($this->form_validation->run()){
#generate a random key
$key = md5(uniqid());
$this->load->model('model_users');
require_once "swift/lib/swift_required.php";
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('xxxxx#gmail.com')
->setPassword('xxxxx');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$messagebody = "<p>Thank you for signing up!</p>";
$messagebody .="<form action= '".base_url()."main/register_user/$key' method='post'>
<input type='submit' value='Activate my Account'> </form> ";
// <p><a href='".base_url()."main/register_user/$key'>Click Here</a> to confirm your account.
// Create a message
$message = Swift_Message::newInstance('CBS Account Activation Message')
->setFrom(array('xxxxx#gmail.com' => 'CBS Group'))
->setContentType("text/html")
->setTo(array($this->input->post('email') => $this->input->post('email')))
->setBody($messagebody)
->setMaxLineLength(100)
;
// Send the message
$result = $mailer->send($message);
//send and email to user
if($this->model_users->add_temp_user($key)){
if($result){
echo "The email has been sent!";
$this->load->view('signup_success');
}
else{
// Failure Message
echo "Could not send mail";
}
}else
echo "Problem adding to database";
#add them to the temp_user db
}
Present I'm trying the use same code in same system it raises an error.
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [ #0]' in C:\xampp\htdocs\code\application\controllers\swift\lib\classes\Swift\Transport\StreamBuffer.php:266 Stack trace: #0 C:\xampp\htdocs\code\application\controllers\swift\lib\classes\Swift\Transport\StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 C:\xampp\htdocs\code\application\controllers\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array) #2 C:\xampp\htdocs\code\application\controllers\swift\lib\classes\Swift\Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 C:\xampp\htdocs\code\application\controllers\main.php(370): Swift_Mailer->send(Object(Swift_Message)) #4 [internal function]: Main->forgot_validation() #5 C:\xampp\htdocs\code\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #6 C:\xampp\htdocs\code\index.php(202): require_once('C:\\xampp\\htdocs. in C:\xampp\htdocs\code\application\controllers\swift\lib\classes\Swift\Transport\StreamBuffer.php on line 266
If i use this same code in another system it's run successfully and sent mail to particular mail id....
I didn't changed the code also.
How can i resolve this problem

SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

magento upgrade 1.5.1.0 >> {1.6.2.0,1.7.0.2,1.8.0.0} i was trying to remove all modules, upgrading directly copying files and with magento downloader, no luck,
every time i get this error. but where and why it fails exactly, how to debug it properly?
Error in file: "Z:\home\www\store\app\code\core\Mage\Core\sql\core_setup\mysql4-upgrade-1.5.9.9-1.6.0.0.php"
- SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
Trace:
#0 Z:\home\www\store\app\code\core\Mage\Core\Model\Resource\Setup.php(645): Mage::exception('Mage_Core', 'Error in file: ...')
#1 Z:\home\www\store\app\code\core\Mage\Core\Model\Resource\Setup.php(437): Mage_Core_Model_Resource_Setup->_modifyResourceDb('upgrade', '0.8.28', '1.6.0.3')
#2 Z:\home\www\store\app\code\core\Mage\Core\Model\Resource\Setup.php(320): Mage_Core_Model_Resource_Setup->_upgradeResourceDb('0.8.28', '1.6.0.3')
#3 Z:\home\www\store\app\code\core\Mage\Core\Model\Resource\Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 Z:\home\www\store\app\code\core\Mage\Core\Model\App.php(417): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 Z:\home\www\store\app\code\core\Mage\Core\Model\App.php(343): Mage_Core_Model_App->_initModules()
#6 Z:\home\www\store\app\Mage.php(683): Mage_Core_Model_App->run(Array)
#7 Z:\home\www\store\index.php(87): Mage::run('', 'store')
#8 {main}
To enable PDO MySQL Debug need to edit this file:
/lib/Varien/Db/Adapter/Pdo/Mysql.php
protected $_debug = true;
then we open this file:
/lib/Zend/Db/Statement/Pdo.php, and replace this line about 234:
throw new Zend_Db_Statement_Exception($e->getMessage(), (int) $e->getCode(), $e);
with this code:
$msg = "SQL ERROR: ". $e->getMessage() . "\n";
$msg .= "SQL QUERY:" . $this->_stmt->queryString."\n";
if(!empty($params)) {
$msg .= "SQL PARAMS: ('". implode("','", $params) ."')\n";
}
$dbsEx = new Zend_Db_Statement_Exception($msg, (int) $e->getCode(), $e);
throw $dbsEx;
so now we will get a folder /var/debug/, and file pdo_mysql.log
in this file we have now full mysql error with full mysql query.
you can easily execute those failing queries in phpmyadmin or edit database table, params, etc.
im happy with it.

Zend Mail keeps giving me a Socket Error

I'm having trouble with sending email using the zend framework. I keep getting a "Could not open socket" error.
I don't know whats wrong here - it used to work on my other host. Ever since I shifted it to another host I can't send emails. I've set up the configuration values to match the new email server.
Heres my code:
$config = array('auth' => _config('mail', 'auth'),
'username' => _config('mail', 'email'),
'password' => _config('mail', 'password'));
$tr = new Zend_Mail_Transport_Smtp(_config('mail', 'smtp'), $config);
$mail = new Zend_Mail();
$mail->setDefaultTransport($tr);
$mail->setFrom(_config('mail','email'), _config('mail','name'));
$mail->addTo($account_email);
$mail->setSubject($mailTitle);
$mail->setBodyText($mailContent);
$mail->send($tr);
EDIt ===
Well the code posted above is my actual code - I don't know whats wrong with it as it used to work on another host.
The following is the exact error I'm getting
Could not open socketstring(1237) "#0 /home/india/public_html/demo/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://mail.indi...')
#1 /home/india/public_html/demo/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect()
#2 /home/india/public_html/demo/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#3 /home/india/public_html/demo/library/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#4 /home/india/public_html/demo/application/controllers/AccountController.php(2153): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp))
#5 /home/india/public_html/demo/library/Zend/Controller/Action.php(513): AccountController->forgetPasswordAction()
#6 /home/india/public_html/demo/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('forgetPasswordA...')
#7 /home/india/public_html/demo/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /home/india/public_html/demo/application/bootstrap.php(26): Zend_Controller_Front->dispatch() #9 /home/india/public_html/demo/html/index.php(4): Bootstrap::run() #10 {main}"
marhaba Ali! ,
digging the code of Zend mail shows http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mail/Protocol/Abstract.php
protected function _connect($remote)
{
$errorNum = 0;
$errorStr = '';
// open connection
$this->_socket = #stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
if ($this->_socket === false) {
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($errorStr);
}
if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
}
return $result;
}
and usually the error number 0 because of
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
from : http://php.net/manual/en/function.stream-socket-client.php
On failure the errno and errstr
arguments will be populated with the
actual system level error that
occurred in the system-level connect()
call. If the value returned in errno
is 0 and the function returned FALSE,
it is an indication that the error
occurred before the connect() call.
This is most likely due to a problem
initializing the socket. Note that the
errno and errstr arguments will always
be passed by reference.
I guess its some firewall blocking the connection to be sent out ,
system-level or network-level error
If you update your answer with more detailed info , i would be happy to help

Zend Framework : Invalid contrller specified (error) ??? Help

I moved my project from windows to ubuntu and had this error while trying to run the project:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with
message 'Invalid controller specified (error)' in
/home/truong/webdev/qtcmsv2/library/Zend/Controller/Dispatcher/Standard.php:248
Stack trace:
#0 /home/truong/webdev/qtcmsv2/library/Zend/Controller/Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
#1 /home/truong/webdev/qtcmsv2/library/Zend/Application/Bootstrap/Bootstrap.php(97):
Zend_Controller_Front->dispatch()
#2 /home/truong/webdev/qtcmsv2/library/Zend/Application.php(366):
Zend_Application_Bootstrap_Bootstrap->run()
#3 /home/truong/webdev/qtcmsv2/index.php(56):
Zend_Application->run()
#4 {main} thrown in
/home/truong/webdev/qtcmsv2/library/Zend/Controller/Dispatcher/Standard.php
on line 248
I did have ErrorController.php file in my default module :
class ErrorController extends Zend_Controller_Action {
/**
* This action handles
* - Application errors
* - Errors in the controller chain arising from missing
* controller classes and/or action methods
*/
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
$this->view->title = 'HTTP/1.1 404 Not Found';
break;
default:
// application error; display error page, but don't change
// status code
$this->view->title = 'Application Error';
break;
}
$this->view->message = $errors->exception;
}
}
My project ran very smoothly in Windows, but the error above always occurs when running in Ubuntu.
How can I solve this problem?? Please help me!
ps : Sorry for my bad English.
Means ZF can't find the error controller so it could be that something is not where it belongs, something is configured incorrectly (like a path), is misnamed, permissions are off, etc. Hard to tell from the info you provided as the error could be in index.php, your bootstrap, config, etc.

displaying page not found error with zend acl

whenever a controller is called if it is not registered in zend acl then we ususally get erro r like this
Fatal error: Uncaught exception 'Zend_Acl_Exception' with message
'Resource 'hsfasfdadsf' not found' in /usr/share/php/libzend-framework-php/Zend/Acl.php:365
Stack trace:
#0 /var/www/update/library/Management/Access.php(55): Zend_Acl->get('hsfasfdadsf')
#1 /usr/share/php/libzend-framework-php/Zend/Controller/Plugin/Broker.php(309): Management_Access->preDispatch(Object(Zend_Controller_Request_Http))
#2 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(941):
isn't there a way to check if the controller and action is registered in zend acl, i tried
if(!$acl->get($controller))
{
$request->setControllerName('error');
$request->setActionName('notfound');
}
but did not work
First solution:
Avoid those exceptions, e.g.
if (!$acl->has($your_resource)) {
// .. handle it the way you need
}
Second one
Handle those exceptions in ErrorController, i.e.:
if ($errors->exception instanceof Zend_Acl_Exception) {
// send needed headers...
// prepare log message...
// render info: resource_not_found.phtml
$this->_helper->viewRenderer('resource_not_found');
}