当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Why is this script sending blank emails without using template in SugarCRM?

问题描述:

This is my code to send emails in SugarCRM CE 6.5.x version,

<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid EntryPoint');

require_once('include/SugarPHPMailer.php');

$msg = new SugarPHPMailer();

$emailObj = new Email();

$defaults = $emailObj->getSystemDefaultEmail();

//Setup template

require_once('XTemplate/xtpl.php');

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

//assign recipients email and name

$rcpt_email = '[email protected]';

$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);

$xtpl->parse();

//$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';

$msg->prepForOutbound();

$msg->AddAddress($email);

$msg->setMailerForSystem();

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: