Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue in Emails::createEmailRecord
#1
When I try to register an email using this code:

$element = array();
$element['saved_toid'] = $correo;
$element['parent_type'] = $modulo;
$element['parent_id'] = vtws_getEntityId($modulo).'x'.$accountid;
$element['from_email'] = $from;
$element['ccmail'] = $ccmail;
$element['bccmail'] = $bccmail;
$element['subject'] = $asunto;
$element['description'] = $cuerpoMensaje;
$emailid = Emails::createEmailRecord($element);

$rdo = send_mail(
$modulo,
$correo,
'xxxxxx',
$from,
$asunto,
$cuerpoMensaje,
$ccmail,
$bccmail,
array(),
$emailid,
'test/logo/logosmall.png'
);

if (!$rdo) {
$mensaje .= 'ERROR: '.$mail->ErrorInfo;
} else {
$mensaje .= 'Se ha enviado el correo al mail '.$datos['email1'] .'<br>';
}

return $mensaje

But it dont works. With debug active shows this:

INFO - PearDatabase ->ADODB disconnect DEBUG - SQL: SET NAMES utf8 DEBUG - EXEC: 0.00052905082702637 micros [START=1602155802.9709, END=1602155802.9714] DEBUG - DEBUG - Prepared sql query being executed : select id from vtiger_ws_entity where name=? DEBUG - Prepared sql query parameters : [Accounts] DEBUG - SQL: select id from vtiger_ws_entity where name=? DEBUG - PARAMS: [Accounts] DEBUG - EXEC: 0.00032305717468262 micros [START=1602155803.2723, END=1602155803.2726] DEBUG - DEBUG - Prepared sql query being executed : SELECT id FROM vtiger_users WHERE is_admin='On' and status='Active' limit 1 DEBUG - SQL: SELECT id FROM vtiger_users WHERE is_admin='On' and status='Active' limit 1 DEBUG - EXEC: 0.00026106834411621 micros [START=1602155803.2727, END=1602155803.273] DEBUG - DEBUG - Entering Users() method ... DEBUG - Entering getColumnFields(Users) method ... DEBUG - Entering getTabid(Users) method ... DEBUG - Prepared sql query being executed : select tabid from vtiger_tab where name=? DEBUG - Prepared sql query parameters : [Users] DEBUG - SQL: select tabid from vtiger_tab where name=? DEBUG - PARAMS: [Users] DEBUG - EXEC: 0.00022006034851074 micros [START=1602155803.2731, END=1602155803.2733] DEBUG - DEBUG - Exiting getTabid method ... DEBUG - Entering getTabid(Users) method ... DEBUG - Exiting getTabid method ... DEBUG - Prepared sql query being executed : SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence FROM vtiger_field WHERE tabid in (?) DEBUG - Prepared sql query parameters : [29] DEBUG - SQL: SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence FROM vtiger_field WHERE tabid in (?) DEBUG - PARAMS: [29] DEBUG - EXEC: 0.00023794174194336 micros [START=1602155803.2734, END=1602155803.2736] DEBUG - DEBUG - Entering getTabid(Users) method ... DEBUG - Exiting getTabid method ... DEBUG - Exiting getColumnFields method ... DEBUG - Exiting Users() method ... Sorry! Attempt to access restricted file.
We are looking for this file path: user_privileges/user_privileges_1.php
We are looking here:
Real file path:
Root dir path: /homepages/35/d489224962/htdocs/corebosPruebas/crm/

What can go wrong? Thanks
Reply
#2
If the code above is all the code you have you are missing some includes and I do not know what this method is:

$emailid = Emails::createEmailRecord($element);

that is a static method call on a function inside the Emails object. As far as I can see that method does not exist in a standard corebos so you may have added it yourself and I don't know what it contains.

You don't need to add any function

You just include modules/Emails/mail.php and you get the function createEmailRecord($email) already available for you.

Have a read at this blog post see if that helps. Compare your createEmailRecord method with the function in mail.php and let me know how it goes.

https://blog.corebos.org/blog/sendemail
Joe
TSolucio
Reply
#3
Hello Joe:

This isn´t all the code. The code are in a funciones.php file, that contains two require_once: This:

require_once 'modules/Emails/Emails.php';
require_once 'modules/Emails/mail.php';

In modules/Emails/Emails.php exists the function:

public static function createEmailRecord($element, $attachmentids = array()) {
global $adb, $log;
$user = Users::getActiveAdminUser();
$elementType = 'Emails';
$webserviceObject = VtigerWebserviceObject::fromName($adb, $elementType);
$handlerPath = $webserviceObject->getHandlerPath();
$handlerClass = $webserviceObject->getHandlerClass();
require_once $handlerPath;
$handler = new $handlerClass($webserviceObject, $user, $adb, $log);
$date = new DateTimeField(null);
if (empty($element['date_start'])) {
$element['date_start'] = $date->getDisplayDate($user);
}
if (empty($element['time_start'])) {
$element['time_start'] = date('H:iConfused');
}
$element['activitytype'] = 'Emails';
if (empty($element['assigned_user_id'])) {
$element['assigned_user_id'] = vtws_getEntityId('Users').'x'.$user->id;
}
if (empty($element['email_flag'])) {
$element['email_flag'] = 'SENT';
}
$result = $handler->create($elementType, $element);
if (!empty($result['id']) && !empty($attachmentids)) {
list($void, $id) = explode('x', $result['id']);
$aids = explode(',', trim($attachmentids, ','));
$query = 'SELECT vtiger_attachments.path, vtiger_attachments.name, vtiger_attachments.attachmentsid
FROM vtiger_attachments
INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
INNER JOIN vtiger_crmentity ON vtiger_attachments.attachmentsid=vtiger_crmentity.crmid
WHERE deleted=0 AND vtiger_seattachmentsrel.crmid = ?';
$insrel = 'INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)';
foreach ($aids as $docid) {
$docrs = $adb->pquery($query, array($docid));
if ($docrs && $adb->num_rows($docrs)==1) {
$adb->pquery($insrel, array($id, $adb->query_result($docrs, 0, 'attachmentsid')));
}
}
return $result['id'];
}
return '';
}
}

And if I comment the line, the email is sent , and dont appear the message.

Sorry! Attempt to access restricted file.
We are looking for this file path: user_privileges/user_privileges_1.php
We are looking here:
Real file path:
Root dir path: /homepages/35/d489224962/htdocs/corebosPruebas/crm/

Only appears when the system try to register it.

Thanks
Reply
#4
the code seems to be correct. activate debug log and see if there is any error in that file. Not SQL log, the vtigercrm log

https://github.com/tsolucio/corebos/blob/master/log4php.properties#L15

set that line to debug and search the file logs/vtigercrm.log for an "error"
Joe
TSolucio
Reply
#5
Hello , Joe. I feel the delay in the answer. I configure the debug but in that file I do not find any error.
The content is too long for publish it in a post. How could I post it so you can see it?
Reply
#6
No problem for the delay, I can imagine... :-)

send it to my email, I'll have a look
Joe
TSolucio
Reply
#7
sent!
Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)