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 Toledoh - April 26, 2015

Hey Ross,

Option 1 would be fine - can you help?

The basic code I use is:

<?php

// process form
if (@$_REQUEST['submitForm']) {

// error checking
$errorsAndAlerts = "";
if (!@$_REQUEST['fullname']) { $errorsAndAlerts .= "You must enter your full name!<br/>\n"; }
if (!@$_REQUEST['edit']) { $errorsAndAlerts .= "You must enter your email!<br/>\n"; }
else if(!isValidEmail(@$_REQUEST['edit'])) { $errorsAndAlerts .= "Please enter a valid email (example: user@example.com)<br/>\n"; }
if (!@$_REQUEST['message']) { $errorsAndAlerts .= "You must enter a message!<br/>\n"; }

// send email user
if (!$errorsAndAlerts) {
$from = $_REQUEST['edit'];
$to = $snippetsRecord['send_to_email'];
$subject = "Contact form submitted from {$_SERVER['HTTP_HOST']}";
$message = <<<__TEXT__
You've received an email from the email form here:
http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}

Full name: {$_REQUEST['fullname']}
Email: {$_REQUEST['edit']}
Rating: {$_REQUEST['rating']}
Message: {$_REQUEST['message']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;
// Note: The above line must be flush left or you'll get an error
// This is a PHP heredoc. See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

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

//
$errorsAndAlerts = "Thanks! We've sent your email.";
$_REQUEST = array(); // clear form values
}

}

?>

Cheers,

Tim (toledoh.com.au)