Zend Mail keeps giving me a Socket Error - zend-framework

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

Related

Laravel 5.2 + mono log critical error send to mail

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))
...

How to resolve Google PHP SDK OpenSSL error: ASN1_get_object:header too long

I'm having trouble getting Google's php sdk to accept the p12 file download directly (twice actually) from Google's Dev Console. The appropriate api permissions should all be in place.
The file is readable by the server and my host (MediaTemple Grid Server) says that there isn't anything that should be blocking this on their end.
Is this a problem in Google's own sdk or am I doing something wrong?
The error is PHP Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Unable to parse the p12 file. Is this a .p12 file? Is the password correct? OpenSSL error: error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long'
[26-Mar-2015 12:39:52 America/New_York] PHP Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Unable to parse the p12 file. Is this a .p12 file? Is the password correct? OpenSSL error: error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long' in /vendor/google/apiclient/src/Google/Signer/P12.php:53
Stack trace:
#0 /vendor/google/apiclient/src/Google/Auth/AssertionCredentials.php(130): Google_Signer_P12->__construct('0\xEF\xBF\xBD\x06\xEF\xBF\xBD\x02\x01\x030\xEF\xBF\xBD...', 'notasecret')
#1 /vendor/google/apiclient/src/Google/Auth/AssertionCredentials.php(107): Google_Auth_AssertionCredentials->makeSignedJwt(Array)
#2 /vendor/google/apiclient/src/Google/Auth/OAuth2.php(306): Google_Auth_AssertionCredentials->generateAssertion()
#3 /vendor/google/apiclient/src/Google/Auth/OAuth2.php(233): Google_Auth_OAuth2->refreshTokenWithAssertion()
#4 /vendor/google/apiclient/src/Google/Service/Resource.php(208): Google_Auth_OAuth2->sign(Object(Google_Http_Request))
#5 /vendor/google/apiclient/src/Google/Service/Datastore.php(232): Google_Service_Resource->call('runQuery', Array, 'Google_Service_...')
#6 /vendor/tomwalder/php-gds/src/GDS/Gateway.php(360): Google_Service_Datastore_Datasets_Resource->runQuery('SomeName', Object(Google_Service_Datastore_RunQueryRequest))
#7 /vendor/tomwalder/php-gds/src/GDS/Gateway.php(305): GDS\Gateway->executeQuery(Object(Google_Service_Datastore_GqlQuery))
#8 /vendor/tomwalder/php-gds/src/GDS/Store.php(270): GDS\Gateway->gql('SELECT * FROM `...', NULL)
#9 /datastore_test/simple.php(28): GDS\Store->fetchOne()
#10 {main}
thrown in /vendor/google/apiclient/src/Google/Signer/P12.php on line 53
Update ... yeah files would be helpful. :)
config.php
<?php
/**
* Template Configuration file for php-gds examples
*
* #author Tom Walder <tom#docnet.nu>
*/
define('GDS_APP_NAME', 'NAME');
define('GDS_KEY_FILE_PATH', dirname(__FILE__) . '/google-generated-keyname.p12');
define('GDS_SERVICE_ACCOUNT_NAME', 'NAME-No');
define('GDS_DATASET_ID', 'DataStore');
$certs = array();
$pkcs12 = file_get_contents( GDS_KEY_FILE_PATH );
// No password
openssl_pkcs12_read( $pkcs12, $certs, "notasecret" );
//echo $certs['cert'];
$data[0] = $certs['cert'];
$data[1] = 'notasecret';
Google's p12.php
// If the private key is provided directly, then this isn't in the p12
// format. Different versions of openssl support different p12 formats
// and the key from google wasn't being accepted by the version available
// at the time.
if (!$password && strpos($p12, "-----BEGIN RSA PRIVATE KEY-----") !== false) {
$this->privateKey = openssl_pkey_get_private($p12);
} else {
// This throws on error
$certs = array();
if (!openssl_pkcs12_read($p12, $certs, $password)) {
throw new Google_Auth_Exception(
"Unable to parse the p12 file. " .
"Is this a .p12 file? Is the password correct? OpenSSL error: " .
openssl_error_string()
);
}
// TODO(beaton): is this part of the contract for the openssl_pkcs12_read
// method? What happens if there are multiple private keys? Do we care?
if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) {
throw new Google_Auth_Exception("No private key found in p12 file.");
}
$this->privateKey = openssl_pkey_get_private($certs['pkey']);
}
Related to Getting "Unable to parse the p12 file..." Error With google-api-php-client

Zend error SQLSTATE[HY000] [1045]

I am having trouble with zend framework and connection with database, I'm trying to create a login, the table is created, and the code apparently is fine, but gives me this:
An error occurred
Application error
Exception information:
Message: SQLSTATE[HY000] [1045] Access denied for user 'onetag51_teste'#'localhost' (using password: YES)
Stack trace:
#0 C:\xampp\Zend\library\Zend\Db\Adapter\Pdo\Mysql.php(109): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 C:\xampp\Zend\library\Zend\Db\Adapter\Abstract.php(860): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 C:\xampp\Zend\library\Zend\Db\Adapter\Abstract.php(930): Zend_Db_Adapter_Abstract->quote('pass1', NULL)
#3 C:\xampp\Zend\library\Zend\Auth\Adapter\DbTable.php(449): Zend_Db_Adapter_Abstract->quoteInto('`password` = ?', 'pass1')
#4 C:\xampp\Zend\library\Zend\Auth\Adapter\DbTable.php(368): Zend_Auth_Adapter_DbTable->_authenticateCreateSelect()
#5 C:\xampp\Zend\library\Zend\Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate()
#6 C:\xampp\htdocs\Eulen\application\controllers\AuthenticationController.php(27): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable))
#7 C:\xampp\Zend\library\Zend\Controller\Action.php(516): AuthenticationController->logininAction()
#8 C:\xampp\Zend\library\Zend\Controller\Dispatcher\Standard.php(308): Zend_Controller_Action->dispatch('logininAction')
#9 C:\xampp\Zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#10 C:\xampp\Zend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#11 C:\xampp\Zend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#12 C:\xampp\htdocs\Eulen\public\index.php(26): Zend_Application->run()
#13 {main}
Request Parameters:
array (
'controller' => 'authentication',
'action' => 'loginin',
'module' => 'default',
)
I was searching for a solution, and some of the possible errors were, spelling errors(I didn't find any), can't connect to phpmyadmin using my pass and user(if I go to the phpmyadmim site, I can enter using the username and password).
I have try several solution but I cant figure it out.
Am I missing something.
file config.ini:
resources.db.params.charset = "utf8"
resources.db.adapter = "pdo_mysql"
resources.db.params.host = localhost
resources.db.params.username = "onetag51_teste"
resources.db.params.password = "*******"
resources.db.params.dbname = "onetag51_eulenhugo"
Its better to put here the authenticationcontroller, maybe the problem is there..
<?php
class AuthenticationController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
public function logininAction()
{
// action body
$authAdapter =$this->getAuthAdapter();
$username='hugo';
$password='pass1';
$authAdapter->setIdentity($username)
->setCredential($password);
$auth =Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if($result->isValid())
{
echo 'valid';
}
else
{
echo 'invalid';
}
}
public function logoutAction()
{
// action body
}
private function getAuthAdapter()
{
$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password');
return $authAdapter;
}
}
ive been talking to a friend of mine, and he told me that i need to set the permission for acesse the phpmyadmim through zend...
How can i do that?
You don't need to use quotations around your adpater, username, password and dbname in your config file. I don't in mine, hope this helps.
I found a bit more reading that might be helpful access denied for user # 'localhost' to database '' because it mentions
You need grant privileges to the user if you want external acess to database(ie. web pages).
in the answer.
There is also this link about adding the users to the database in mysql.
Hope this helps
So the problem was related with the priveleges, thanks for ARJMP, ive tryed changed the priveleges but thee host didnd let me do it, so what i did was create a local database using xamp and try the login with the database that ive created in xamp, and it worked...

Zend_Log with mail

Has anyone succeed to send an mail(SMTP GOOGLE) with Zend_Log.I found this http://framework.zend.com/manual/en/zend.log.writers.html
Chapter 32.2.4. Writing to Email but by default it's using mail(), but I want to use SMTP.So until now my code looks like this:
$mailconf = array('ssl'=>'ssl',
'auth' => 'login',
'username' => 'mymail#gmail.com',
'password' => 'mypass',
'port'=>'465');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailconf);
$mail = new Zend_Mail();
$mail->setFrom('from.website#example.com')
->addTo('mysecondmail#site.com');
$writer = new Zend_Log_Writer_Mail($mail);
// On fixe le sujet du mail
$writer->setSubjectPrependText('Important Log Events');
// Only email warning level entries and higher.
$writer->addFilter(Zend_Log::WARN);
$loggerZendMail = new Zend_Log();
$loggerZendMail->addWriter($writer);
$loggerZendMail->log('unable to connect to database',Zend_Log::WARN);
I'm getting this error:
Fatal error: Uncaught exception 'Zend_Log_Exception' with message 'Unable to send mail' in C:\wamp\www\zf_log\Zend\Log\Writer\Mail.php:256 Stack trace: #0 C:\wamp\www\zf_log\Zend\Log.php(84): Zend_Log_Writer_Mail->shutdown() #1 C:\wamp\www\zf_log\Zend\Controller\Action.php(512): Zend_Log->__destruct() #2 C:\wamp\www\zf_log\Zend\Controller\Action.php(512): IndexController->indexAction() #3 C:\wamp\www\zf_log\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('indexAction') #4 C:\wamp\www\zf_log\Zend\Controller\Front.php(945): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 C:\wamp\www\zf_log\index.php(30): Zend_Controller_Front->dispatch() #6 {main} thrown in C:\wamp\www\zf_log\Zend\Log\Writer\Mail.php on line 256
Any suggestions?
You need to set the transport for Zend_Mail to use
Example:
Zend_Mail::setDefaultTransport($transport);
I would check if SMTP is enabled on server.
Use TLS instead of SSL also check if the port 587 works
so the below config should work
$mailconf = array('ssl'=>'tls', 'auth' => 'login', 'username' => 'mymail#gmail.com', 'password' => 'mypass', 'port'=>'587');

Zend_Auth : DB table structure

So followed all the basic tutorials. Am using Zend 1.8 but i keep getting this exception when using Zend_Auth_DB. Any ideas, there is only one row in the table.
Exception information:
Message: The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.
Stack trace:
#0 C:\projects\BHAA_ZEND\library\Zend\Auth\Adapter\DbTable.php(306): Zend_Auth_Adapter_DbTable->_authenticateQuerySelect(Object(Zend_Db_Select))
#1 C:\projects\BHAA_ZEND\library\Zend\Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate()
#2 C:\projects\BHAA_ZEND\application\controllers\LoginController.php(79): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable))
#3 C:\projects\BHAA_ZEND\application\controllers\LoginController.php(38): LoginController->getAuthAdapter(Array)
#4 C:\projects\BHAA_ZEND\library\Zend\Controller\Action.php(512): LoginController->processAction()
#5 C:\projects\BHAA_ZEND\library\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('processAction')
#6 C:\projects\BHAA_ZEND\library\Zend\Controller\Front.php(945): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#7 C:\projects\BHAA_ZEND\library\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch()
#8 C:\projects\BHAA_ZEND\library\Zend\Application.php(328): Zend_Application_Bootstrap_Bootstrap->run()
#9 C:\projects\BHAA_ZEND\public\index.php(33): Zend_Application->run()
#10 {main}
Here's the offending code.
public function getAuthAdapter(array $params)
{
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('login')
->setIdentityColumn('username')
->setCredentialColumn('password');
//->setCredentialTreatment('MD5(?)');
// pass to the adapter the submitted username and password
$authAdapter->setIdentity($username)->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
// success : store database row to auth's storage system
// (not the password though!)
$data = $authAdapter->getResultRowObject(null, 'password');
$auth->getStorage()->write($data);
//$this->_redirect('/');
return $this->_helper->redirector('index','index');
} else {
// failure: clear database row from session
$this->view->message = 'Login failed.';
return $this->render('index');
}
return $result;
}
Have you read the documentation for Zend_Auth_Adapter_DbTable? - Yes, but i'm not sure if it cleared or muddied my understanding.
Do you have a valid connection to the database? - Yup, have a working CRUD app with the same DB config.
What is the structure of your users table? -
Did you specify the identity and credential columns correctly to the constructor of Zend_Auth_Adapter_DbTable? - See code above, i believe so.
Did you also specify the username/password you're trying to authenticate? - Yup, have a Zend form submitting these variables.
What is the SQL query that is causing the error? I think this is it.
SELECT `isp_partners_view`.*, (CASE WHEN `password` = '*****' THEN 1 ELSE 0 END) AS `zend_auth_credential_match` FROM `isp_partners_view` WHERE (`username` = '*****')
You have given the error, but there are number of other questions I'd ask to try to troubleshoot this:
Have you read the documentation for Zend_Auth_Adapter_DbTable?
Do you have a valid connection to the database?
What is the structure of your users table?
Did you specify the identity and credential columns correctly to the constructor of Zend_Auth_Adapter_DbTable?
Did you also specify the username/password you're trying to authenticate?
What is the SQL query that is causing the error? You can view the query this way:
$select = $authAdapter->getDbSelect();
print $select . "\n";