Selecting an outbound email account

We have had one outbound email account used for everything on the system form the start, but a new custom module needs to send email via a different account. So I have added this to suiteCRM in the outbound email profiles and called it Orders

Typically I use this script when needing to send an email

$emailObj = new Email();
        $defaults = $emailObj->getSystemDefaultEmail();
        $mail = new SugarPHPMailer();
        $mail->setMailerForSystem();
        $mail->From = $defaults['email'];
        $mail->FromName = $defaults['name'];
        $mail->Subject = "subject";
        $mail->Body = 'hello there.';
        $mail->addAttachment($file, $filename);
        $mail->prepForOutbound();
        $mail>AddAddress("address");
        if ($sendemail) {@$mail->Send();}
        unset($mail);

what would I need to change / add to use the orders profile?

Many Thanks
Pete

I have found out how to do this, under the user account make sure you add an outbound mail account and then the code looks like this:

$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailer();
$mail->From = $current_user->email1;
$mail->FromName = "$current_user->name";
$mail->Subject = "test";
$mail->Body = 'lalalal;
$mail->prepForOutbound();
$mail->AddAddress('email');
$mail->Send();
unset($mail);

Not fully sure why I need these lines below as I am not using the $defaults object, but it seems to fail in it is not included.

$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
2 Likes