Contact Form Problems

6 posts by 2 authors in: Forums > CMS Builder
Last Post: April 2, 2013   (RSS)

By Jason - March 21, 2013

Hi Zick,

It's possible that there is an issue with the SMTP server that's sending this message.  To make sure that this is the case, we can try using the CMSB sendMessage() function to send the email.  This is a really robust function that takes care of all the header and mime type issues for us.  Here is an example:

  // send email user
    if (!$errorsAlerts) {
        $from        = $_REQUEST['email'];
        $to          = "webdev@domain.net";
        $subject     = "{$_REQUEST['firstname']} {$_REQUEST['lastname']} submitted a message at {$_SERVER['HTTP_HOST']}";
        $message     = <<<__TEXT__
<div style='background-color:#006BAF; padding:24px; font-size:22px; font-family:Arial; color:#FFF; margin-bottom:12px;'> Please contact {$_REQUEST['firstname']} {$_REQUEST['lastname']}
</div>

<div style='padding:24px; font-size:14px; font-family:Arial; color:#003A46; margin-bottom:0px;'>
<strong>First Name:</strong> {$_REQUEST['firstname']}<br />
<strong>Last Name:</strong> {$_REQUEST['lastname']}<br />
<strong>Title:</strong> {$_REQUEST['title']}<br />
<strong>Company:</strong> {$_REQUEST['company']}<br />
<strong>Address:</strong> {$_REQUEST['address']}<br />
{$_REQUEST['address2']}<br />
<strong>City:</strong> {$_REQUEST['city']}<br />
<strong>State:</strong> {$_REQUEST['state']}<br />
<strong>Zipcode:</strong> {$_REQUEST['zipcode']}<br />
<strong>Phone Number:</strong> {$_REQUEST['phone']}<br />
<strong>Email:</strong> {$_REQUEST['email']}<br /><br />
<strong>Message:</strong> {$_REQUEST['message']}
</div>

<div style='background-color:#CFE2A7; padding:24px; font-size:14px; font-family:Arial; color:#FFF; margin-bottom:12px;'>
The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.</div>
__TEXT__;
 
     $mailErrors = sendMessage(array(
       'to'      =>  $to,
       'from'    =>  $from,
       'subject' =>  $subject,
       'html'    =>  $message,
       
     ));
     
     if ($mailErrors) { die("Error sending email: $mailErrors"); }

      //
      $errorsAlerts = "Thank you for taking the time to contact us. A representative will be in contact.";
      $_REQUEST = array(); // clear form values
  }

Give this a try and see if you get the same results. If you do, I would suggest contacting your host to see if there are issues with the mail server.

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Mikey - March 21, 2013

Jason... as always many thanks for your help! Your solution solved the issue.

Contact Form if statement for $to

By Mikey - April 2, 2013

Anyone have any suggestion on how to add an if statement to the contact form for who receives the message? See the example in red below of what I'm trying to achieve.

// send email user
    if (!$errorsAlerts) {
        $from        = $_REQUEST['email'];
$to          = if $business_detailsRecord['email_to']; // If no Department email exist then Business Details email address is used.
$to          = else if $it_departmentRecord['email_to']; // Else if an email address exist for the Department, then the Department email address trumps Business Details.
$to          = else 'business@domain.net'; // Otherwise if no email address exist for either Business Details nor Department, then there's a fall back email address.
        $subject     = "{$_REQUEST['firstname']} {$_REQUEST['lastname']} submitted a message at {$_SERVER['HTTP_HOST']}";
        $message     = <<<__TEXT__
<div style='background-color:#006BAF; padding:24px; font-size:22px; font-family:Arial; color:#FFF; margin-bottom:12px;'> Please contact {$_REQUEST['firstname']} {$_REQUEST['lastname']}
</div>

<div style='padding:24px; font-size:14px; font-family:Arial; color:#003A46; margin-bottom:0px;'>
<strong>First Name:</strong> {$_REQUEST['firstname']}<br />
<strong>Last Name:</strong> {$_REQUEST['lastname']}<br />
<strong>Title:</strong> {$_REQUEST['title']}<br />
<strong>Company:</strong> {$_REQUEST['company']}<br />
<strong>Address:</strong> {$_REQUEST['address']}<br />
{$_REQUEST['address2']}<br />
<strong>City:</strong> {$_REQUEST['city']}<br />
<strong>State:</strong> {$_REQUEST['state']}<br />
<strong>Zipcode:</strong> {$_REQUEST['zipcode']}<br />
<strong>Phone Number:</strong> {$_REQUEST['phone']}<br />
<strong>Email:</strong> {$_REQUEST['email']}<br /><br />
<strong>Message:</strong> {$_REQUEST['message']}
</div>

<div style='background-color:#CFE2A7; padding:24px; font-size:14px; font-family:Arial; color:#FFF; margin-bottom:12px;'>
The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.</div>
__TEXT__;
 
     $mailErrors = sendMessage(array(
       'to'      =>  $to,
       'from'    =>  $from,
       'subject' =>  $subject,
       'html'    =>  $message,
       
     ));
     
     if ($mailErrors) { die("Error sending email: $mailErrors"); }

      //
      $errorsAlerts = "Thank you for taking the time to contact us. A representative will be in contact.";
      $_REQUEST = array(); // clear form values
  }

Contact Form if statement for $to

By Jason - April 2, 2013

Hi Zick,

You can set up your if statement like this:

if ($business_detailsRecord['email_to']) {
    $to = $business_detailsRecord['email_to'];
  }
  elseif ($it_departmentRecord['email_to']) {
    $to = $it_departmentRecord['email_to'];
  }
  else {
    $to = "business@domain.net";
  }

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Contact Form if statement for $to

By Mikey - April 2, 2013

Thanks Jason,

Works like a charm!

You're the best.

Zick