Login +

How To ? / Sending mails

To send a simple email reusing configurations entered during the installation:

$email = new SLS_Email();
$email->openConnection();
$email->setCharset("UTF-8");
$email->addRecipient("laurent.bientz@sillysmart.org", "To");
$email->setSender($this->_generic->getMailConfig('defaultSender').'@'.$this->_generic->getMailConfig('defaultDomain'), $this->_generic->getMailConfig('defaultNameSender'));
$email->setReply($this->_generic->getMailConfig('defaultReply').'@'.$this->_generic->getMailConfig('defaultDomain'), $this->_generic->getMailConfig('defaultNameReply'));
$email->setReturn($this->_generic->getMailConfig('defaultReturn').'@'.$this->_generic->getMailConfig('defaultDomain'), $this->_generic->getMailConfig('defaultNameReturn'));
$email->setSubject(SLS_String::makeEmailSubject("My subject"));
$msgHtml = 'Hi,<br /><br />It\'s a wonderful <strong>HTML email</strong> sent by SLS_Email.<br /><br />Greetz,<br />SillySmart Team';
$email->setHtml($msgHtml);
$email->setPlain(strip_tags(SLS_String::br2nl($msgHtml)));
$email->addAttachment("Public/Files/user/new_york_1_f5563c326c.jpg");
$email->compileMail();
$email->send();
$email->closeConnection();

Render:

If you just want to send a mail using default settings:

$email = new SLS_Email();
$email->addRecipient("laurent.bientz@sillysmart.org", "To");
$email->setSubject("Simple subject");
$email->setHtml("Simple <strong>HTML</strong> content.");
$email->send();


References

  1. SLS_Email - Send mail from a distant SMTP
  2. SLS_String - Tool SLS_String - String Treatment