Email Form

4 posts by 3 authors in: Forums > CMS Builder
Last Post: April 27, 2015   (RSS)

By Toledoh - April 23, 2015

Hi all. 

Is there a way to use the standard Emailform.php, but have it register in the outgoing email log in cmsb? 

And possibly then use the mail settings as well, as I'm using Mandril. 

Thank!

Cheers,

Tim (toledoh.com.au)

By ross - April 24, 2015

Hi Tim

Thanks for posting!

Best place to start here is with the fact I am not actually that familiar with Emailform.php. Having said that though, if it's just a simple script that sends an email, there should be a way to hook into CMS Builders Outgoing Mail system.  

One option would be to include CMS Builder's library files into your emailform.php code and then just use the sendMail() function we built.

Another option would be to just manually enter a record in CMS Builder's Outgoing Mail table in the code as it sends your email.  

Of the two, option one is likely quicker as most of the functionality is built right in once you've included CMS Builder's library files.  

Do either options catch your eye?

Let me know what you think. Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Dave - April 27, 2015

Hi Tim, 

How it works is mail() is a PHP function that sends through the default server mail system that is configured.  

What we're doing now is calling our own function sendMessage() in /lib/common.php that sends mail with the configuration options from the CMSB.  

If you're into writing your own PHP code you can always look in the library functions for more info as we often have programmer notes and instructions in there.  Here's some examples from the header of sendMessage()

  // 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",
  ));

  // 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
  ));

  // show errors
  if ($errors) { die($errors); }

So I'd try replacing this:

$mailResult = @mail($to, $subject, $message, "From: $from");
if (!$mailResult) { die("Mail Error: $php_errormsg"); }

With this:

  $errors = sendMessage(array(
    'from'    => $from,
    'to'      => $to,
    'subject' => $subject,
    'text'    => $message,
  ));
  if ($errors) { die($errors); }

Also make sure "From" is an email you are allowed to send from (*@yourdomain.com) or it might be blocked by some servers.  If you want to be able to click "Reply" to reply to client emails use the "Reply-To" header.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com