Hi!
recently i learn about bussiness hooks. I need capture a web lead and before_create send a email to the user.
i can`t find the email field in $bean->email or $bean->emailAddress->getPrimaryAddress or ... i try but i cant find the solution.
Here is muy php code.
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class leads_custom{
function gancho_contacto(&$bean, $event, $arguments){
// make sure the status was actually changed to closed
// $bean->fetched_row['status'] is the stored status of the case
// $bean->status is the status it was changed to
if ($bean->fetched_row['status'] !== 'Interesado NO contactado' && $bean->status === 'Interesado NO contactado' && $bean->lead_source === 'Self Generated' && $bean->productointeresado_c === 'Secretariado Administrativo'){
require_once('include/SugarPHPMailer.php');
require_once("modules/Administration/Administration.php");
$mail = new SugarPHPMailer();
$admin = new Administration();
$admin->retrieveSettings();
if ($admin->settings['mail_sendtype'] == "SMTP") {
$mail->Host = $admin->settings['mail_smtpserver'];
$mail->Port = $admin->settings['mail_smtpport'];
if ($admin->settings['mail_smtpauth_req']) {
$mail->SMTPAuth = TRUE;
$mail->Username = $admin->settings['mail_smtpuser'];
$mail->Password = $admin->settings['mail_smtppass'];
}
$mail->Mailer = "smtp";
$mail->SMTPKeepAlive = true;
}
else {
$mail->mailer = 'sendmail';
}
$mail->From = $admin->settings['notify_fromaddress'];
$mail->FromName = $admin->settings['notify_fromname'];
$mail->ContentType = "text/html"; //"text/plain"
$mail->Subject = "A pocos pasos del titulo Secretariado Administrativo!";
global $sugar_config;
global $app_list_strings;
global $locale;
//no va porque no hay nada guardado todavia
// $emails = $bean->emailAddress->getAddressesByGUID($bean->id, 'Leads');
$mail->Body = $bean->emailAddress->getPrimaryAddress($bean);
$mail->AddAddress($bean->email, $bean->contact_name); if ($mail->send()) {
//cambio el estado a interesado contactado
$bean->status = 'Interesado CONTACTADO';
}
else
{
$GLOBALS['log']->info("Mailer error: " . $mail->ErrorInfo);
}
}
}
}
?>
Please help!!!!
Thanks for all the information on the forum!
Manuel Lupiaņez


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks