Page 1 of 1

Contact form with options not properly working

Posted: Thu Aug 02, 2012 4:33 am
by mlungisi
Hi there

Please help, the form suppose to send email to different email address depending on enquiry option selected. Currently the form doesn’t do that and I cant seem to find or fix this issue.

Contact page code

Code: Select all

      <?php
    require_once('src/config.php');
    $VarSecurity = new VarSecurity();

    $enquiry = NULL;
    $chk_Locate = FALSE;

    if((isset($_GET['enquiry']) && $_GET['enquiry']=='Locate a dealer/distributor')||(isset($_POST['enquiry']) && $_POST['enquiry']=='Locate a dealer/distributor')){
       $chk_Locate=TRUE;
    }

    if(isset($_GET['enquiry']) && $_GET['enquiry'] == 'CC'){
       $query_recipients = array(array('Complaint', 'csm@mycompany.com'),
                         array('Suggestion', 'csm@mycompany.com'),
                         array('Compliment', 'csm@mycompany.com'));
       $enquiry = '<input type="hidden" name="enquiry" id="enquiry" value="CC">';
    }

    else{
       $query_recipients = array(array('Locate a dealer/distributor', 'sales@mycompany.com'),
                         array('Technical support', 'technical@mycompany.com'),
                         array('Back orders', 'backorders@mycompany.com'),
                         array('Product enquiry', 'sales@mycompany.com'),
                         array('Catalog request', 'sales@mycompany.com'),
                         array('New customer enquiry', 'sales@mycompany.com'),
                         array('Existing customers - logon', 'dealers@mycompany.com'),
                         array('Existing customers - orders', 'weborder@mycompany.com'),
                         array('Report web problems', 'webmaster@mycompany.com'));
    }

    $enquiry_options = '';
    $selected_notes = '';
    $item = NULL;
    if(isset($_GET['item'])){
       $item=$_GET['item'];
    }
    foreach($query_recipients as $key => $val){
       if((isset($_POST['enquiry']) && $_POST['enquiry'] == $val[0])||(isset($_GET['enquiry']) && $_GET['enquiry'] == $val[0])){
          $selected = $val[0].' : '.$item;
          if($val[0]=='Existing customers - logon'||$val[0]=='Technical support'||$val[0]=='Catalog request'||$val[0]=='Product enquiry'||$val[0]=='New customer enquiry'||$val[0]=='Existing customers - orders'||$val[0]=='Catalog request'){
             $selected_notes = '<br><p>&bull; If you are an EXISTING Radiant dealer please enter you Radiant account number so that we can correctly deal with your enquiry. Please enter your username and password for verification purposes (your login details are not sent with the enquiry). If you are already logged in you will not need to enter this information</p>
                         <p>&bull; Please enter </p><br>
                         <p>Radiant only supplies to appointed distributors, and not direct to the public.</p>
                         <p>However, our showrooms are open to the public daily, where you can view our product range and get assistance with your queries.</p>';
          }elseif($val[0]=='Locate a dealer/distributor'){
             $selected_notes = '<p>&bull; Please supply your area details in the message body, as well as surrounding suburbs</p><br>';
          }
       }
       $enquiry_options .= '<option>'.$val[0].'</option>';
       $recpt_email = $val[1];
    }
    if(empty($selected)){
       $selected = 'Select option';
       $selected_notes = '<br><p>&bull; If you are an EXISTING Radiant dealer please enter you Radiant account number so that we can correctly deal with your enquiry. Please enter your username and password for verification purposes (your login details are not sent with the enquiry). If you are already logged in you will not need to enter this information</p><br>
                         <p>Radiant only supplies to appointed distributors, and not direct to the public.</p>
                         <p>However, our showrooms are open to the public daily, where you can view our product range and get assistance with your queries.</p>';
    }

    $cont_ref = NULL;
    $ref_number = NULL;


    if(isset($_POST['name'])){
       $VarSecurity->protectform();
       
       if ($Session->ID()==NULL){
          $query = @mysql_query('SELECT Accnr FROM WEB_Cust WHERE Uname="'.$_POST['dealer_username'].'" AND Pword="'.md5($_POST['dealer_password']).'" AND active=1 AND AXblocked!=2 LIMIT 0,1');
          $login = @mysql_num_rows($query);
          if($login==1){
             $cust_verify = 'Dealer is verified';
             $contact_email = 'info2@mycompany.com';
             $Session->Logout(NULL);
          } else {
             $cust_verify = 'Dealer not verfied: username/password supplied but did not match our records.';
          }
       }elseif($Session->ID()!=NULL){
             $cust_verify = 'Dealer is verified';
             $contact_email = 'info2@radiant.co.za';
       }else{
          $cust_verify = 'Dealer not verfied: username/password not supplied.';
       }
       
       if(isset($_POST['enquiry']) && $_POST['enquiry'] == 'CC'){
          $done = false;
          while(!$done){
             $ref_number = 'web'.strtolower(substr(str_replace(' ', '', $_POST['company']), 0, 1)).substr(md5(microtime()), 0, 5);
             
             $unique_query = @mysql_query('SELECT * FROM web_cms_feedback WHERE ref_number="'.$ref_number.'"');
             
             if(@mysql_num_rows($unique_query) == 0){
                $done = true;
             }
          }
          
          $insert_query = @mysql_query('INSERT INTO web_cms_feedback (Web_ref, Name, Surname, Company, Accnr, Email, Tel_cell, Enquiry, Message)
                            VALUES ("'.$ref_number.'", "'.$_POST['name'].'", "'.$_POST['surname'].'", "'.$_POST['company'].'", "'.$_POST['accnr'].'", "'.$_POST['email'].'", "'.$_POST['tel'].'", "'.$_POST['enquiry'].'", "'.$_POST['message'].'")');
          $insert_data = @mysql_fetch_array($insert_query);
          $cont_ref = '<br>
                   <h4>Reference: '.$ref_number.'</h4>
                   You will receive an automated response to your email address shortly';
       }
       
       $_POST['recipient_email'] = $contact_email.','.$recpt_email;
       if(isset($ref_number)){
          $_POST['subject'] = 'Radiant Group: '.$ref_number.': '.$_POST['enquiry'];
       }else{
          $_POST['subject'] = 'Radiant Group: '.$_POST['enquiry'];
       }
       $_POST['sender_email'] = $_POST['email'];
       $_POST['cc'] = $_POST['email'].', Radiant Group <radiant.orders@gmail.com>';
       $_POST['body'] = '<p>Name: ' . $_POST['name'] . '</p>'
                      . '<p>Surname: ' . $_POST['surname'] . '</p>'
                      . '<p>Company: ' . $_POST['company'] . '</p>'
                      . '<p>Radiant Account No.: ' . $_POST['accnr'] . '</p>'
                      . '<p>Account No. verification: ' . $cust_verify . '</p>'
                      . '<p>Email: ' . $_POST['email'] . '</p>'
                      . '<p>Tel/cell: ' . $_POST['tel'] . '</p>'
                      . $_POST['enquiry'] . ': ' . $_POST['message'];
                      
       if(Email::Send($_POST, NULL)){
          $message = 'Your feedback has been sent'.$cont_ref;
       } else {
          $message = 'There was an error sending your feedback';
       }
    }

          $Newproducts = new NewProducts();
          
          global $body;
          $body = '<div class="column-310 float-left">
                   <div class="block-khaki home-highlights">
                      <div class="padding-10">
                         <h1 class="text-white">Welcome to Radiant</h1>
                         <br/>
                         <p>We are committed to a brighter future by creating lighting and electrical solutions which are beautiful by design and inspired by the environment. We are certain that you will find lighting and electrical products that compliment your life space and enlighten you.</p>
                      </div>
                   </div>
                   <div class="gap-hoz-small"></div>
                   <div class="block-khaki home-newprod">
                      <div class="padding-10">
                         <h1 class="text-white">New Products</h1>
                         </div>
                         '.$Newproducts->Display().'
                   </div>
                </div>';
          echo $body;
    ?>
            <div class="gap-vert float-left"></div>
            <div class="column-630 float-left">
               <h1 class="text-grey">Contact feedback</h1>
                <br/>
                <p class="message"><?php echo (isset($message) ? $message : NULL); ?></p>
                <br/>
                <form id="form" action="?page=contact-feedback" method="post">
                    <div class="form order-form">
                       <?php if($Session->ID()==NULL && $chk_Locate==FALSE):?>
                        <div><label>Radiant Account No.</label><div><input type="text" name="accnr" id="accnr" class="input" maxlength="100" value="&nbsp;"/></div></div>
                        <p class="clear"></p>
                        <div><label>User name</label><div><input type="text" name="dealer_username" id="dealer_username" class="input dealer-input"/></div></div>
                        <p class="clear"></p>
                        <div><label>Password</label><div><input type="password" name="dealer_password" id="dealer_password" class="input dealer-input"/></div></div>
                        <p class="clear"></p>
                        <?php elseif($chk_Locate==FALSE):?>
                        <input type="hidden" name="accnr" id="accnr" class="input" maxlength="100" value="<?php echo $Session->ID();?>"/>
                        <?php endif?>
                        <p class="clear"></p><br />
                        <div><label>Name</label><div><input type="text" name="name" id="name" value="" class="input"/></div></div>
                        <p class="clear"></p>
                        <div><label>Surname</label><div><input type="text" name="surname" id="surname" value="" class="input"/></div></div>
                        <p class="clear"></p>
                        <div><label>Company</label><div><input type="text" name="company" id="company" value="" class="input"/></div></div>
                        <p class="clear"></p>
                        <div><label>Email</label><div><input type="text" name="email" id="email" class="input" maxlength="100"/></div></div>
                        <p class="clear"></p>
                        <div><label>Tel/cell</label><div><input type="text" name="tel" id="tel" class="input" maxlength="50"/></div></div>
                        <p class="clear"></p>
                        <div><label>Enquiry</label><div><select name="enquiry" id="enquiry" class="select"><option selected="selected"><?php echo $selected ?></option><?php echo $enquiry_options ?></select></div></div>
                        <p class="clear"></p>
                        <div><label>Message</label><div><textarea name="message" id="message" rows="5" cols="10" class="textarea"></textarea></div></div>
                    </div>
                    <div>
                    <?php echo $selected_notes?>
                        <br/>
                        <?php echo $enquiry?>
                        <input type="submit" id="submit" value="submit" class="submit-khaki" onclick="javascript:return mail.Send();"/>
                        <p class="clear"></p>
                        <br/>
                    </div>
                </form>
               <br />
              <p><input type="submit" value="Back" class="submit-khaki float-right" onclick="javascript:window.history.back();"/></p>
            </div> 
Config.php code

Code: Select all

<?php
$db_server = '100.1001.1001.10';
$db = 'Database';
$db_username = 'username';
$db_password = 'password';

$title = 'MyCompany';
$env_repo = getenv('php_repository');
if(!empty($env_repo)){
   $classes = $env_repo;
} else {
   $classes = 'src/Classes/';
}
$pagination = array('items_per_page'=>300);
$default_page = 'Home';
$sales_email = 'weborder@mycompany.com';
$contact_email = 'info@mycompany.com';
$image_path = 'http://www.mycompany.com/src/img/email/';
?>

Re: Contact form with options not properly working

Posted: Thu Aug 02, 2012 5:18 am
by social_experiment
could you paste the code again using the PHP Code button; it's a bit unreadable at the moment

Re: Contact form with options not properly working

Posted: Thu Aug 02, 2012 8:29 am
by mlungisi
@social_experiment i've fixed the code, please check again.

Re: Contact form with options not properly working

Posted: Thu Aug 02, 2012 9:42 pm
by califdon
What does the code do now?

Re: Contact form with options not properly working

Posted: Fri Aug 03, 2012 1:55 am
by mlungisi
For now the code sends email to: info@mycompany.com the email in config.php "$contact_email = 'info@mycompany.com';" and webmaster@mycompany.com the last email in the arrays "array('Report web problems', 'webmaster@mycompany.com'));". It doesn't matter what subject the user chooses, the emails are sent to those two email addresses.

Re: Contact form with options not properly working

Posted: Fri Aug 03, 2012 2:36 am
by social_experiment
The value for a selected email is contained within $_POST['enquiry'] but i can't seem to find where you use the value when sending the email, unless it happens in function not shown here;

Code: Select all

<?php
$_POST['sender_email'] = $_POST['email'];
       $_POST['cc'] = $_POST['email'].', Radiant Group <radiant.orders@gmail.com>';
       $_POST['body'] = '<p>Name: ' . $_POST['name'] . '</p>'
                      . '<p>Surname: ' . $_POST['surname'] . '</p>'
                      . '<p>Company: ' . $_POST['company'] . '</p>'
                      . '<p>Radiant Account No.: ' . $_POST['accnr'] . '</p>'
                      . '<p>Account No. verification: ' . $cust_verify . '</p>'
                      . '<p>Email: ' . $_POST['email'] . '</p>'
                      . '<p>Tel/cell: ' . $_POST['tel'] . '</p>'
                      . $_POST['enquiry'] . ': ' . $_POST['message'];
?>

Re: Contact form with options not properly working

Posted: Fri Aug 03, 2012 2:59 am
by mlungisi
I've just searched all the code for $_POST['enquiry'] and 'enquiry' but there is no other page with the two code snips but on the contact page.

Re: Contact form with options not properly working

Posted: Fri Aug 03, 2012 3:21 am
by social_experiment
Could you paste the code that actually sends the email