I would like to use Swift Mailer.

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 10, 2015   (RSS)

By rconring - July 10, 2015

I have maoved some of my sites to a more secure server that requires SMTP authentication to send mail.  I have been using Machform embeded forms since it supports SMTP auth but would like to create some lighter forms with PHP using simple Bootstrap contact forms and use Swift Mailer that is now included with cmsb to send.  Do you have any examples or other information on how to accomplish this?

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By Dave - July 10, 2015

Hi Ron,

Our internal function is called sendMessage() and can be found in /lib/common.php.

Here's some examples from the function header:

// send an email message with attachments.
// If text _and_ html are specified the email client will decide what to display.
/*
  // Minimal Example:
  $errors = sendMessage(array(
    'from'    => "from@example.com",
    'to'      => "to@example.com",
    'subject' => "Enter subject here, supports utf-8 content",
    'text'    => "Text message content",
  ));
  if ($errors) { die($errors); }

  // Full Featured Example:
  $errors = sendMessage(array(
    'from'    => "from@example.com",
    'to'      => "to@example.com",
    'subject' => "Enter subject here, supports utf-8 content",
    'text'    => "Text message content",
    'html'    => "<b>HTML</b> message content",
    'headers' => array(
      "CC"          => "cc@example.com",
      "BCC"         => "bcc@example.com",
      "Reply-To"    => "rt@example.com",
      "Return-Path" => "rp@example.com",
    ),
    'attachments' => array(
      'simple.txt'  => 'A simple text file',
      'dynamic.csv' => $csvData,
      'archive.zip' => $binaryData,
      'image.jpg'   => file_get_contents($imagePath),
    ),
    //'disabled' => false, // set to true to disable sending of message
    //'logging' => false, // set to false to disable logging (if logging is already enabled) - used for background mailers
  ));
  if ($errors) { die($errors); }

Hope that helps!  Let me know any questions.

Dave Edis - Senior Developer
interactivetools.com

By Dave - July 10, 2015

And something else you might find helpful.  Go to: Admin > Email Templates and select "Developers: Show sendMessage() PHP".  If you create an email template in that section it will generate the sendMessage() code for you.

Dave Edis - Senior Developer
interactivetools.com