if (!TEST) {
if ($hash != 'forwarded' || !sizeof($forwardedby)) {
$fromname = $cached[$messageid]["fromname"];
$fromemail = $cached[$messageid]["fromemail"];
$subject = $cached[$messageid]["subject"];
# Add two lines to replace the placeholder in subject line
$newsdate = date('l j F');
$subject = eregi_replace("\[NEWSDATE\]",$newsdate,$subject);
#
if (!$mail->send("", $destinationemail, $fromname, $fromemail, $subject)) {
//changed to allow attribs in subject & inclusion of [NEWSDATE] for date in subject.
if (!$mail->send("", $destinationemail, $fromname, $fromemail, plugAttributes($subject, $email))) {
function addAttachments($msgid,&$mail,$type) {
//added this function, adapted from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
//should be used as upper case like [FIRST NAME] just as with attribs in body.
//also can include current date using [NEWSDATE]
function plugAttributes($str="", $email="")
{
# Add two lines to replace the placeholder in subject line bhugh, 9/2006
$newsdate = date('l j F');
$str = eregi_replace("\[NEWSDATE\]",$newsdate,$str);
#
$custom_list=getUserAttributeValues($email);
while (list($AttribName,$AttribValue) = each ($custom_list)) {
foreach($custom_list AS $AttribName => $AttribValue) {
$upAttribName=strtoupper($AttribName);
$str = trim(str_replace("[{$upAttribName}]",$AttribValue,$str));
}
}
return $str;
}
function addAttachments($msgid,&$mail,$type) {
stephenrs wrote:
so, beginning around line 451, my code looks like:
- Code: Select all
if (!TEST) {
$theSubject = plugAttributes($cached[$messageid]["subject"], $email);
if (!$mail->send("", $email, $cached[$messageid]["fromname"], $cached[$messageid]["fromemail"],$theSubject)) {
logEvent("Error sending message $messageid to $email");
}
}
}
//srs added this function, clipped from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
function plugAttributes($str="", $email="")
{
$custom_list=getUserAttributeValues($email);
while (list($AttribName,$AttribValue) = each ($custom_list)) {
foreach($custom_list AS $AttribName => $AttribValue)
$str = trim(str_replace("[{$AttribName}]",$AttribValue,$str));
}
return $str;
}
no other changes were needed, and the plugAttributes() function can also be used to customize the body of the message...
i didn't test your version, but either you were setting $theSubject too early, or your ereg_replace() wasn't working the way you expected (also, your foreach line was commented out).
thanks for the perfect starting point.
if (!$mail->send("", $destinationemail, $fromname, $fromemail, $subject)) {
if (!$mail->send("", $destinationemail, $fromname, $fromemail,plugAttributes($subject,$email,$messageid))) {
//added this function, adapted from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
//should be used as upper case like [FIRST NAME] just as with attribs in body.
//also can include current date using [NEWSDATE]
//also can include list name (title) using [LISTNAME]
//also can include template name using [TEMPLATENAME]
function plugAttributes($str="", $email="",$messageid=0)
{
# Add two lines to replace the placeholder in subject line bhugh, 9/2006
$newsdate = date('l j F');
$str = eregi_replace("\[NEWSDATE\]",$newsdate,$str);
#
$custom_list=getUserAttributeValues($email);
while (list($AttribName,$AttribValue) = each ($custom_list)) {
foreach($custom_list AS $AttribName => $AttribValue) {
$upAttribName=strtoupper($AttribName);
$str = trim(str_replace("[{$upAttribName}]",$AttribValue,$str));
}
}
$sql = "SELECT {$GLOBALS["tables"]["message"]}.template, {$GLOBALS["tables"]['template']} .title ";
$sql .="FROM {$GLOBALS["tables"]['template']} LEFT JOIN {$GLOBALS["tables"]["message"]} ON ";
$sql .= "{$GLOBALS["tables"]['template']} .id = {$GLOBALS["tables"]["message"]}.template ";
$sql .= "WHERE {$GLOBALS["tables"]["message"]}.id=".$messageid;
$templatename =Sql_Query($sql);
$templatename = Sql_Fetch_array($templatename);
if (!empty($templatename)){
$templatename = $templatename['title'];
} else {
$templatename='';
}
$str = eregi_replace("\[TEMPLATENAME\]",$templatename,$str);
$sql = "SELECT {$GLOBALS["tables"]['list']} .name ";
$sql .="FROM {$GLOBALS["tables"]['list']} LEFT JOIN {$GLOBALS["tables"]["listmessage"]} ON ";
$sql .= "{$GLOBALS["tables"]['list']} .id = {$GLOBALS["tables"]["listmessage"]}.listid ";
$sql .= "WHERE {$GLOBALS["tables"]["listmessage"]}.id=".$messageid;
$listname =Sql_Query($sql);
$listname = Sql_Fetch_array($listname);
$listname = $listname['name'];
$str = eregi_replace("\[LISTNAME\]",$listname,$str);
return $str;
}
Return to Contributions: Plug-ins, Add-ons, Mods
Users browsing this forum: No registered users and 1 guest