Assistance needed with older email sending code - after a form page is submitted. NOT a form-generator plugin question.

7 posts by 4 authors in: Forums > CMS Builder
Last Post: January 16, 2017   (RSS)

By Codee - January 13, 2017

Greetings,

I have run into an issue ~ that most likely I caused somewhere but my ignorance has been too severe to correct properly and timely.  I have some code I was using successfully until recently...it was working on CMSB versions from 2.5 to 3.06.  I utilize a form page that upon submission by a website visitor creates/populates a record in the CMSB database, sends an email to the website owner and/or sends an email to the submitter (to the email address they provided), and then redirects the website visitor to a thank you page.  Up until a short time ago, the code was working fine but now the functions work fine EXCEPT for sending the email. It's as if the email portion of the code is simply ignored but the next part of the code (redirecting to thank you page) is not.  Below is the code that I place in the header of the page and below that is the code for the form within the html/php portion of the page:

-----BEGINNING OF CODE IN THE HEADER AREA (COMES FIRST....BEFORE THE CMSB SECTION INCLUDES AND THE BODY, TITLE, ETC. AND INCLUDES SOME ERROR-CHECKING)---------:

<?php
  require_once "/home/xxxxx/public_html/xxxwebsitenamexxx.com/aTHadmin231/lib/init.php";

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

  // error checking
  $errorsAndAlerts = "";
  if (!@$_REQUEST['name'])  { $errorsAndAlerts .= "Please tell us your name!<br/>\n"; }
 
  if (!@$_REQUEST['address'])  { $errorsAndAlerts .= "Please tell us your address! It is required in order to give you an accurate quote.<br/>\n"; }
 
   if (!@$_REQUEST['sqfootage'])  { $errorsAndAlerts .= "Please provide us the square footage of your home!  It is required in order to give you an accurate quote.<br/>\n"; }
   
  if (!@$_REQUEST['consent'])  { $errorsAndAlerts .= "Please check the box giving your consent for us to contact you!<br/>\0"; }
    
  // turn off strict mysql error checking for: STRICT_ALL_TABLES
  mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

  // add record
  if (!@$errorsAndAlerts) {
    mysql_query("INSERT INTO `{$TABLE_PREFIX}marketing` SET
                                        name                = '".mysql_real_escape_string( $_REQUEST['name'] )."',
                      telephone        = '".mysql_real_escape_string( $_REQUEST['telephone'] )."',
                      cell             = '".mysql_real_escape_string( $_REQUEST['cell'] )."',
                      email            = '".mysql_real_escape_string( $_REQUEST['email'] )."',
                      reachrobert      = '".mysql_real_escape_string( $_REQUEST['reachrobert'] )."',
                      address             = '".mysql_real_escape_string( $_REQUEST['address'] )."',
                      city             = '".mysql_real_escape_string( $_REQUEST['city'] )."',
                      zip                 = '".mysql_real_escape_string( $_REQUEST['zip'] )."',
                      sqfootage        = '".mysql_real_escape_string( $_REQUEST['sqfootage'] )."',
                      tell_us_more     = '".mysql_real_escape_string( $_REQUEST['tell_us_more'] )."',
                      consent          = '".(@$_REQUEST['consent'] ? '1' : '0')."',

                      createdDate      = NOW(),
                      updatedDate      = NOW(),
                      createdByUserNum = '0',
                      updatedByUserNum = '0'")
    or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
    $recordNum = mysql_insert_id();

$to="freequotes@xxxwebsitenamexxx.com";
$subject="New Customer Free Quote Request Submitted from xxxwebsitenamexxx.com";

$message=<<<__TEXT__
A new quote request has been submitted for your review. Please login to the content manager to view the ad in the "Marketing" section. This submission is from

{$_REQUEST['name']}

who can be reached by telephone at
{$_REQUEST['telephone']}

or by their cell phone at
{$_REQUEST['cell']}

Their email address is
{$_REQUEST['reachrobert']}

The square footage of their home at

{$_REQUEST['address']} in {$_REQUEST['city']} with zip code {$_REQUEST['zip']}

 is
 
{$_REQUEST['sqfootage']} square feet

They are also enquiring about
{$_REQUEST['tell_us_more']}

__TEXT__;

mail($to,$subject,$message);
    // redirect to thank you page
header('Location: customerthankyou.php');
exit;
  }

}

?>

------END OF CODE IN THE HEADER AREA BEFORE THE CMSB SECTION INCLUDES AND THE BODY, TITLE, ETC...-------

------ CODE FOR THE FORM ON THE HTML/PHP PORTION OF THE PAGE--------:

<!--display record code begins-->
                                <form method="post" action="">
                                <input type="hidden" name="submit" value="1" />
                                
                                <?php if (@$errorsAndAlerts): ?>
                                  <div style="color: red; font-weight: bold; font-size: 16px;"><br/>
                                    <?php echo $errorsAndAlerts; ?><br/><br/>
                                  </div>
                                <?php endif ?>
                                    <center>
                                <h1>Get A FREE xxxServiceNamexxx Quote by Submitting this Form</h1>
                            
                                <table width="900" border="0" cellspacing="0" cellpadding="2">
                                <tr>
                                  <td style="vertical-align:top" width="300">Name</td>
                                  <td><input type="text" name="name" value="<?php echo htmlspecialchars(@$_REQUEST['name']) ?>" size="30" /><br/><br/></td>
                                </tr>
                                
                                <tr>
                                  <td style="vertical-align:top">Telephone</td>
                                  <td><input type="text" name="telephone" value="<?php echo htmlspecialchars(@$_REQUEST['telephone']) ?>" size="20" /><br/><br/></td>
                                </tr>
                                
                                <tr>
                                  <td style="vertical-align:top">Cell Phone or Alternate Phone</td>
                                  <td><input type="text" name="cell" value="<?php echo htmlspecialchars(@$_REQUEST['cell']) ?>" size="20" /><br/><br/></td>
                                </tr>
                                <tr>
                                  <td style="vertical-align:top"></td>
                                  <td><input type="hidden" name="email" value="" /><br/><br/></td>
                                </tr>
                                
                                <tr>
 
                                <tr>
                                  <td style="vertical-align:top">Email</td>
                                  <td><input type="text" name="reachrobert" value="<?php echo htmlspecialchars(@$_REQUEST['reachrobert']) ?>" size="40" /><br/><font size="2" face="arial">[Your email address will be kept private and will not be sold or redistributed.]<br/><br/></td>
                                </tr>
                                
                                <tr>
                                  <td style="vertical-align:top">Size of Home</td>
                                  <td><input type="text" name="sqfootage" value="<?php echo htmlspecialchars(@$_REQUEST['sqfootage']) ?>" size="6" /> Sq Feet<br/><font size="2" face="arial">[The total square footage of your home is required in order to give you an accurate quote.]<br/><br/></td>
                                </tr>
                                
                                <tr>
                                  <td style="vertical-align:top">Street Address</td>
                                  <td><input type="text" name="address" value="<?php echo htmlspecialchars(@$_REQUEST['address']) ?>" size="70" /> <br/><font size="2" face="arial">[The address of your home is required in order to give you an accurate quote.]<br/><br/></td>
                                </tr>
                                <tr>
                                  <td style="vertical-align:top">City</td>
                                  <td><input type="text" name="city" value="<?php echo htmlspecialchars(@$_REQUEST['city']) ?>" size="12" /><br/><br/></td>
                                </tr>
                                <tr>
                                  <td style="vertical-align:top">Zip Code</td>
                                  <td><input type="text" name="zip" value="<?php echo htmlspecialchars(@$_REQUEST['zip']) ?>" size="7" /><br/><br/></td>
                                </tr>
                                
                                <tr>
                                  <td style="vertical-align:top">Tell us any additional question you may have; or, let us know more about how we can help you...</td>
                                  <td><textarea name="tell_us_more" cols="40" rows="7" value="<?php echo htmlspecialchars(@$_REQUEST['tell_us_more']) ?>" /></textarea> <br/><br/></td>
                                </tr>
                                <tr>
                                  <td style="vertical-align:top">Consent</td>
                                  <td><input name="consent" type="checkbox" value="1" <?php checkedIf(@$_REQUEST['consent'], '1') ?> />
                                            <br/>
                                      <font size="2">By checking this consent box and clicking the "Submit Form" button I hereby request information for and from CompanyName, xxxwebsitenamexxx.com and the office for CompanyOwnerName, and consent to having them, their agent or representative(s) contact me via telephone, FAX, email and/or cell
                                          phone as needed to facilitate this process.  I have read, or have had read to me, the above consent.  I have also had an opportunity to ask questions about its content, and by signing below (clicking submit), I agree to the above procedures.  
                                        </font>
                                      </td>
                                </tr>
                                </table>
                                </center>
                                <br/>
                                <center>
                                <input type="submit" name="add" value="Click to SUBMIT Form &gt;&gt;" />
                                <br/><br/><br/><br/>
                                <input type="reset" value="reset form" /><br/><br/>
                                </center>
                                </form>
                            <!--display record code ends-->

----END OF FORM PAGE CODE--

Thank you in advance for any help to correct this!

By Codee - January 13, 2017

I "MAY" have just figured part of the problem.  After driving myself bonkers for hours off-and-on I decided to take a step backward to the simple and just test sending email from CMSB (from multiple CMSB-powered sites) using the password reset feature with the PHP built-in mail function by default, as a test => my results are as follows:

- non-GoDaddy hosted sites = 100% success in receiving the emails

- GoDaddy shared hosting sites = 100% failure in receiving the emails (and of course CMSB reflects them being processed...but they simply never show up).

So, anyone else come across this? I've always preferred utilizing the php built-in mail function by default...but if that no longer works, is there a fix...or do I switch to the SMTP options?

Any and all help is tremendously appreciated!

By Codee - January 15, 2017

Yes, Tim ~ that post from Djulia/Greg is actually what prompted me.  The script didn't work on several sites...but it ran (but no email received)...so I tested it on a non-GoDaddy hosted site and it ran AND sent the email.  I went back and tested the "forgot password" feature on multiple GoDaddy hosted sites and received no email...then tested the forgot password function on non-GD hosted sites and got the email every time.

By Toledoh - January 15, 2017

I would be going to support for GoDaddy and asking them... obviously something on their set-up that's broken.  Sorry I can't help more!

Cheers,

Tim (toledoh.com.au)

By ross - January 16, 2017

Hi there.

I agree with Tim that you'll need to get GoDaddy involved on this one.  

I recommend showing them just the script you saw from the other thread and ask them to trouble shoot that.

The main thing with that script is that it's completely independent of CMS Builder. Once that script works, CMS Builder should as well.

Post back any updates you have from GoDaddy.

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/