AnsweredAssumed Answered

Why is my script to send emails sending emails blank without using template?

Question asked by Sohan Tirpude on Jan 20, 2015
Hello everyone, this is my code to send emails in SugarCRM CE 6.5.x version,


//Setup template
$xtpl = new XTemplate('custom/modules/Users/ChangePassword.html');

//assign recipients email and name
$rcpt_email = '';
$rcpt_name = 'Sohan';

//Set RECIPIENT's address
$email = $msg->AddAddress($rcpt_email, $rcpt_name);

//Send msg to users
$template_name = 'User';

//Assign values to variables in template
$xtpl->assign('EMAIL_NAME', $rcpt_name);
//$body = "Hello Sohan, It's been 80 days that you haven't changed your password. Please take some time out to change password first before it expires.";
$msg->From = $defaults['email'];
$msg->FromName = $defaults['name'];
$msg->Body = from_html(trim($xtpl->text($template_name)));
//$msg->Body = $body;
$msg->Subject = 'Change Password Request';

//Send the message, log if error occurs
if (!$msg->Send()){
     $GLOBALS['log']->fatal('Error sending e-mail: ' . $msg->ErrorInfo);

Now this script send blanks emails, and when I hardcoded body part then
it is takes those message written in body, and sends an email. So,
please help me here.