Mail template with module fields

Hi,

I use SugarCRM pro 7.6 and I want to send via PHP a mail with a pre-created template.

In the template I want to insert a lot of fields from different modules (Accounts, Contacts, Quotes...).

How can I create the template with the fields placeholders?

How can I parsing the template to insert the values of the fileds in the text of the mail?

I searched a solution on google but I find only this page https://developer.sugarcrm.com/2013/09/25/parsing-an-email-template-programatically/ which doesn't consider fields from different modules.

Thanks for the help

Best regards

Stefano

Parents
  • Hi Stefano Mapelli,

    You can create your pre-created template with predefined tags for eg.

    Hi {LEAD_NAME},
    Thanks for contacting us for {CASE_SUBJECT}. We have created a case against {ACCOUNT_NAME}.

    And in your php before sending email you can use 

    $mail = new SugarPHPMailer();
    $mail->Subject = $template->subject;
    $mail->prepForOutbound();
    $mail->setMailerForSystem();

    //Retrieve specific lead

    $lead = BeanFactory::retrieveBean('Leads', "36 character lead id");
    $body_html = str_replace('{LEAD_NAME}',$lead->name, $template->body_html);

    //Retrieve specific account

    $account = BeanFactory::retrieveBean('Accounts', "36 character account id");
    $body_html = str_replace('{ACCOUNT_NAME}',$account->name, $body_html);

    //Retrieve specific case

    $case = BeanFactory::retrieveBean('Cases', "36 character case id");

    $body_html = str_replace('{CASE_SUBJECT}',$case->subject, $body_html);
    $mail->IsHTML(true);
    $mail->From = $admin->settings['notify_fromaddress'];
    $mail->FromName = $admin->settings['notify_fromname'];
    $mail->AddAddress($email);
    $mail->Body = from_html($body_html);
    $mail->AltBody = from_html($body);

    hope this help!!!

Reply Children
No Data