Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP formmailer doesn't work on all PC or MAC machines

    Good morning,

    I am writing for some help with a PHP form mailer I found online. The script works great and sends the email with attachment from my PC laptop (Windows 7, Firefox and IE) but when I send it from my MAC (OS X, Safari and Firefox) the form does not send the email at all. Also, my client tried out the form on his PC and it never sent the email either. How is this script only working on one of these three computers? Any help is very much appreciated!

    PHP Code:
    <?PHP
    /*
        Contact Form from HTML Form Guide
        This program is free software published under the
        terms of the GNU Lesser General Public License.
        See this page for more info:
        http://www.html-form-guide.com/contact-form/contact-form-attachment.html
    */
    require_once("./include/fgcontactform.php");
    require_once(
    "./include/captcha-creator.php");

    $formproc = new FGContactForm();
    $captcha = new FGCaptchaCreator('scaptcha');

    $formproc->EnableCaptcha($captcha);

    //1. Add your email address here.
    //You can add more than one receipients.
    $formproc->AddRecipient('sales@dependableprint.com'); //<<---Put your email address here


    //2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
    // and put it here
    $formproc->SetFormRandomKey('E6bZFICMgOhOnxI');

    $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);

    if(isset(
    $_POST['submitted']))
    {
       if(
    $formproc->ProcessForm())
       {
            
    $formproc->RedirectToURL("thank-you.php");
       }
    }

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
          <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
          <title>Order Form</title>
          <link rel="STYLESHEET" type="text/css" href="contact.css" />
          <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
          <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
    </head>
    <body>

    <!-- Form Code Start -->
    <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>

    <fieldset >
    <legend>Please Fill in the Details Below</legend>

    <input type='hidden' name='submitted' id='submitted' value='1'/>
    <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
    <input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />

    <div class='short_explanation'>* required fields</div>

    <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>

    <div class='fieldContainer'>
        <span class="formText"><label for='name' >Your Full Name*: </label></span><br/>
        <input name='name' type='text' id='name' value='<?php echo $formproc->SafeDisplay('name'?>' size="65" maxlength="50" /><br/>
        <span id='contactus_name_errorloc' class='error'></span>
    </div>

    <div class='fieldContainer'>
        <label for='bizName' >Business Name*: </label><br/>
        <input name='bizName' type='text' id='bizName' value='<?php echo $formproc->SafeDisplay('bizName'?>' size="65" maxlength="50" /><br/>
        <span id='contactus_bizName_errorloc' class='error'></span>
    </div>

    <div style="width:700px; height:55px; padding:0; margin-top:8px; margin-bottom: 10px;">

    <div style="width:235px; height:50px; float:left; padding:0;">
    <span class="formText">Address*</span><br />
      <input name='address' type='text' id='address' value='<?php echo $formproc->SafeDisplay('address'?>' size="25" maxlength="50" /><br />
        <span id='contactus_address_errorloc' class='error'></span></p>
    </div>
        
        <div style="width:190px; height:50px; float:left; padding:0;">
    <span class="formText">City*</span><br />
      <input name='city' type='text' id='city' value='<?php echo $formproc->SafeDisplay('city'?>' size="25" maxlength="50" /><br />
        <span id='contactus_city_errorloc' class='error'></span></p>
        </div>
        
        <div style="width:100px; height:50px; text-align:center; float:left;">
    <span class="formText">State*</span><br />
    <input name='state' type='text' id='state' value='<?php echo $formproc->SafeDisplay('state'?>' size="4" maxlength="2" /><br />
        <span id='contactus_state_errorloc' class='error'></span>
        </div>
        
        <div style="width:75px; height:50px; text-align:center; float:left;">
    <span class="formText">Zipcode*</span><br />
    <input name='zipcode' type='text' id='zipcode' value='<?php echo $formproc->SafeDisplay('zipcode'?>' size="7" maxlength="5" /><br />
        <span id='contactus_zipcode_errorloc' class='error'></span>
        </div>
        
        </div>



    <div class='fieldContainer'>
    <div style="width:350px; float:left; ">
        <label for='email' >Email Address*:</label>
        <br />
    <input name='email' type='text' id='email' value='<?php echo $formproc->SafeDisplay('email'?>' size="50" /><br />
    <span id='contactus_email_errorloc' class='error'></span>
    </div>
        <div style="width:225px; float:left; ">
        <label for='phone' >Phone Number*:</label><br/>
        <input name='phone' type='text' id='phone' value='<?php echo $formproc->SafeDisplay('phone'?>' size="15" maxlength="12" /> 
        <span class="fineprint">ex: 555-123-4567</span><br/>
        <span id='contactus_phone_errorloc' class='error'></span></div>
    </div>

    <p>&nbsp;</p>



    <div id="tableRow0">

    <div id="tableRow1">
    <div id="tableRow1-1"><span class="formText">Letterhead</span></div>
      <div id="tableRow1-2"><label>
        <select name="letterhead" id="letterhead">
          <option value="None" selected="selected"></option>
    <option value="70lb Bright White">70lb Bright White</option>
    <option value="25% Cotton w/watermark">25% Cotton w/watermark</option>
    <option value="Linen">Linen</option>
    <option value="Laid">Laid</option>
    <option value="30% recycled white">30% recycled white</option>
    </select>
      </label></div>
    <div id="tableRow1-3">
    &nbsp;</div>
    <div id="tableRow1-4">
    <label><span class="formText">QTY</span>
      <select name="letterheadQty" id="letterheadQty">
        <option value="0" selected="selected">0</option>
        <option value="500">500</option>
        <option value="1000">1000</option>
        <option value="1500">1500</option>
        <option value="2000">2000</option>
        <option value="2500">2500</option>
      </select>
      </label>
    </div>
    <div class="clear"></div>
    </div>

    <div class="clear"></div>

    <div id="tableRow1">
    <div id="tableRow1-1">
    <span class="formText">Envelopes</span></div>
    <div id="tableRow1-2">
    <label>
      <select name="envelopes" id="envelopes">
        <option value="None" selected="selected"></option>
        <option value="#10 White Business">#10 White Business</option>
        <option value="#9 Return">#9 Return Env</option>
        <option value="6 3/4 white sm">6 3/4 white sm</option>
        <option value="#10 Window">#10 Window </option>
        <option value="#10 Security">#10 Security</option>
        <option value="#10 Peal &amp; Seal">#10 Peal &amp; Seal</option>
        <option value="#10 Peal &amp; Seal Security">#10 Peal &amp; Seal Security</option>
        <option value="#10 Linen or Laid">#10 Linen or Laid</option>
        <option value="#10 25% cotton watermarked">#10 25% cotton watermarked</option>
        <option value="6x9 White Catalog">6x9 White Catalog</option>
        <option value="6x9 Brown Catalog">6x9 Brown Catalog</option>
        <option value="6x9 White Brochure">6x9 White Brochure</option>
        <option value="9x12 White Catalog">9x12 White Catalog</option>
        <option value="9x12 White Brochure">9x12 White Brochure</option>
        <option value="10x13 White Catalog">10x13 White Catalog</option>
        <option value="10x13 White Brochure">10x13 White Brochure</option>
        <option value="10x15 White Catalog">10x15 White Catalog</option>
        <option value="10x15 White Brochure">10x15 White Brochure</option>
    </select>
      </label>
    </div>
      <div id="tableRow1-3">
      &nbsp;</div>
      <div id="tableRow1-4">
      <label><span class="formText">QTY</span>
      <select name="envelopesQty" id="envelopesQty">
        <option value="0" selected="selected">0</option>
        <option value="500">500</option>
        <option value="1000">1000</option>
        <option value="1500">1500</option>
        <option value="2000">2000</option>
        <option value="2500">2500</option>
      </select>
      </label>
      </div>
    </div>

    <div class="clear"></div>

    <div id="tableRow1">
    <div id="tableRow1-1">
    <span class="formText">Business Cards</span></div>
    <div id="tableRow1-2">
    <label>
      <select name="businessCards" id="businessCards">
        <option value="None" selected="selected"></option>
        <option value="Std 80lb White Card Black Ink">Std 80lb White Card Black ink</option>
        <option value="Std 80lb White Card 1 color ink">Std 80lb White Card 1 Color ink</option>
        <option value="Std 80lb White Card Full Color">Std 80lb White Card Full Color</option>
        <option value="14pt Full color Glossy photo card">14pt Full color Glossy Photo card</option>
    </select>
      </label>
    </div>
      <div id="tableRow1-3">&nbsp;</div>
      <div id="tableRow1-4">
      <label><span class="formText">QTY</span>
      <select name="businessCardsQty" id="businessCardsQty">
        <option value="0" selected="selected">0</option>
        <option value="250">250</option>
        <option value="500">500</option>
        <option value="1000">1000</option>
      </select>
      </label></div>

    </div>

    <div class="clear"></div>

    <div id="tableRow1">
    <div id="tableRow1-1">
    <span class="formText">Carbonless</span>
    </div>
    <div id="tableRow1-2">
    <label>
          <select name="carbonless" id="carbonless">
            <option value="None" selected="selected"></option>
        <option value="2 Part">2 Part</option>
        <option value="3 Part">3 Part</option>
        <option value="4 Part">4 Part</option>
        <option value="5 Part">5 Part</option>
    </select>
      </label></div>
      <div id="tableRow1-3">&nbsp;</div>
      <div id="tableRow1-4">
      <label><span class="formText">QTY</span>
      <select name="carbonlessQty" id="carbonlessQty">
        <option value="0" selected="selected">0</option>
        <option value="250 Sets">250 Sets</option>
        <option value="500 Sets">500 Sets</option>
        <option value="1000 Sets">1000 Sets</option>
      </select>
      </label>
      </div>
    </div>

    <div class="clear"></div>

    <div id="tableRow1">
    <div id="tableRow1-1"><span class="formText">Copies</span></div>
    <div id="tableRow1-2">
    <label>
          <select name="copies" id="copies">
            <option value="None" selected="selected"></option>
        <option value="1 Side B&amp;W">1 side B&amp;W</option>
        <option value="2 sides B&amp;W">2 sides B&amp;W</option>
        <option value="1 side color">1 side color</option>
        <option value="2 sides color">2 sides color</option>
    </select>
      </label>
    </div>
    <div id="tableRow1-3">
    &nbsp;</div>
    <div id="tableRow1-4">
    <label><span class="formText">QTY</span>
      <select name="copiesQty" id="copiesQty">
        <option value="0" selected="selected">0</option>
        <option value="250">250</option>
        <option value="500">500</option>
        <option value="1000">1000</option>
        <option value="1500">1500</option>
        <option value="2000">2000</option>
        <option value="2500">2500</option>
        <option value="5000">5000</option>
      </select>
      </label></div>
      </div>

    <div class="clear"></div>

    <div id="tableRow1">
    <div id="tableRow1-1"><span class="formText">Postcards</span></div>
    <div id="tableRow1-2">
    <label>
          <select name="postcards" id="postcards">
            <option value="None" selected="selected"></option>
        <option value="80lb White-Blk ink 4x6 1 side">80lb White-Blk ink 4x6 1 side</option>
        <option value="80lb White-Blk ink 4x6 2 sides">80lb White -Blk ink 4x6 2 sides</option>
        <option value="14pt Full color 2 sides 4x6">14pt Full Color 2 sides 4x6</option>
        <option value="other size">other size</option>
    </select>
      </label></div>
      <div id="tableRow1-3">&nbsp;</div>
      <div id="tableRow1-4">
      <label><span class="formText">QTY</span>
      <select name="postcardsQty" id="postcardsQty">
        <option value="0" selected="selected">0</option>
        <option value="250">250</option>
        <option value="500">500</option>
        <option value="1000">1000</option>
        <option value="2500">2500</option>
        <option value="5000">5000</option>
      </select>
      </label>
      </div>
    </div>

    </div><!-- end tableRow0 -->


    <p>&nbsp;</p>
    <p>&nbsp;</p>

    <div class='container'>
    <label for='message'><span class="formText">Please include any comments or special instructions we should know about:</span></label><br/>
        <span id='contactus_message_errorloc' class='error'></span>
        <span class="alignCenter"><textarea rows="5" cols="100" name='message' id='message'><?php echo $formproc->SafeDisplay('message'?></textarea></span>
    </div>

    <div style="width:600px; height:60px; text-align:center">
    <label for='photo' >Attach Your Art File:</label><br/>
        <input type="file" name='photo' id='photo' /><br/>
        <span id='contactus_photo_errorloc' class='error'></span>
    </div>


    <div class='container'>
        <div align="center"><img alt='Captcha image' src='show-captcha.php?rand=1' id='scaptcha_img' /></div>
        <div style="text-align:center"><label for='scaptcha' >Enter the code above here:</label>
        <span class="alignCenter"><input type='text' name='scaptcha' id='scaptcha' maxlength="10" /></span><br/>
        <span class="alignCenter"><span id='contactus_scaptcha_errorloc' class='error'></span></span></div>
        
        <div class='short_explanation'>Can't read the image?
        <a href='javascript: refresh_captcha_img();'>Click here to refresh</a>.</div>
    </div>


    <div class='container'>
    <p style="text-align:center"><input type='submit' name='Submit' value='Submit' /></p>
    </div>

    </fieldset>
    </form>
    <!-- client-side Form Validations:
    Uses the excellent form validation script from JavaScript-coder.com-->

    <script type='text/javascript'>
    // <![CDATA[

        var frmvalidator  = new Validator("contactus");
        frmvalidator.EnableOnPageErrorDisplay();
        frmvalidator.EnableMsgsTogether();
        frmvalidator.addValidation("name","req","Please provide your name");
        
        frmvalidator.addValidation("bizName","req","Please provide your business's name.");

        frmvalidator.addValidation("email","req","Please provide your email address");

        frmvalidator.addValidation("phone","req","Please provide a contact number.");
        
        frmvalidator.addValidation("address","req","Please provide your shipping address.");
        
        frmvalidator.addValidation("city","req","Please provide your city.");
        
        frmvalidator.addValidation("state","req","Please fill in.");
        
        frmvalidator.addValidation("zipcode","req","Please fill in.");

        frmvalidator.addValidation("message","maxlen=2048","The exceeds the maximum limit. Please go back and shorten, then submit again. Thank you!");

        frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp;tif;tiff;eps;ai;pdf;ppt;pptx;doc;docx;","File format is not supported. Please upload one of the following formats: jpg, jpeg, gif, png, bmp, tiff, tiff, eps, ai, pdf, ppt, pptx, doc, docx.");

        frmvalidator.addValidation("scaptcha","req","Please enter the code in the image above");

        document.forms['contactus'].scaptcha.validator
          = new FG_CaptchaValidator(document.forms['contactus'].scaptcha,
                        document.images['scaptcha_img']);

        function SCaptcha_Validate()
        {
            return document.forms['contactus'].scaptcha.validator.validate();
        }

        frmvalidator.setAddnlValidationFunction("SCaptcha_Validate");

        function refresh_captcha_img()
        {
            var img = document.images['scaptcha_img'];
            img.src = img.src.substring(0,img.src.lastIndexOf("?")) + "?rand="+Math.random()*1000;
        }

    // ]]>
    </script>


    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Two very important questions here:
    1) How is this form sending email? - SMTP or sendmail?
    2) IF sendmail, do you have an appropriate sendmail equivalent installed on the mac and the windows machine?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much for your reply! I thought the form was sending it POST. That code I posted in my original thread is the actual form itself that then calls on the recaptcha and other files. But, the weird thing is that the form sends successfully from Firefox and IE on my PC laptop, but not from my client's PC or my MAC. I hope this answers your question correctly?

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    No it doesn't answer it correctly.

    You clearly have Apache and PHP installed on your laptop. Do you also have something like fakesendmail or msmtp?

    Next, do the other computer that can't send email also have it installed?

    Also the form and the email are two different things. The form should work on all computers assuming you have the correct html path for the form tag so the browser submits successfully. Sending email is different. You need to be clear as to which one is the real issue because your first post you say the emails don't work on the other computers and in this reply you're talking about the form submitting saying it doesn't work on the other computers.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I apologize for not answering correctly. I am not a programmer but have a very basic understanding of this type of coding.

    As far as I know, I am unaware of anything specific installed on my own laptop, like Apache. I have never heard of fakesendmail or msmtp, so if it is on my laptop, I am unaware of it.

    From my client's PC and my MAC at work, I have no idea if Apache, fakesendmail or msmtp are installed. If I had to guess, I would say they aren't.

    The form does work and sends the form correctly with the file attachment from FF and IE from my PC laptop. The problem is when my client submits the form from his PC (he used Firefox) or when I tried submitting the form from my MAC (using safari and firefox) at work, the form does redirect to the thank-you.php BUT the email never arrives. So, on the user end, the thank you page does come up, but is not always sending the email successfully. This is why I am confused because it is sending the email successfully from my PC laptop, but not from my client's PC or my MAC.

    Should I be using a method other than POST for this type of thing, since the code says there is a bug?

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    POST is fine and is designed for form submissions.

    Now.. You've never heard of apache, and to the best of your knowledge it's not installed.. so what webserver are you using on your laptop? - IIS?

    fakesendmail/msmtp will not be on any machine unless you specifically download it so NO you don't have it.

    Where exactly are you putting these files on your computer? - Whats the file path? - Reason I ask is that this all sounds a bit strange to me. Most people who are writing webpages and using php know what apache is yet you've no idea and claim your scripts are working and sending email. If you're using IIS then that would explain it but if you're not then something weird is happening.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The entire website and domain name are hosted at Go Daddy and the form's files are all in one folder on the server. The hosting specs are as follows:
    OS/Hosting Type is: Linux / Shared Hosting.
    Hosting configuration: 2.1
    PHP Version: 5.2
    Bandwidth: unlimited
    IIS: I don't see a line for this in the dashboard when I login

    It is very strange that the email works perfectly from my laptop, but when I do it from my MAC or when my client tried to submit it, the email never arrived. This is why I am very confused but wondering if it has something to do with Go Daddy's individual setup? Thank you for your attention this!

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Ok now we're making progress. See when you wrote this below it literally sounded like you were running this ON your laptop.

    Quote Originally Posted by jewelsmac66 View Post
    The script works great and sends the email with attachment from my PC laptop (Windows 7, Firefox and IE)
    Have you done the usual like checking the spam filters?

    Can you also supply us the URL to the form?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My apologies!! I meant that I was using my laptop PC as the computer I was using, and then my client used his PC and then also tried submitting the form from my MAC. So I thought it was a PC vs. MAC thing, but it can't be since my client and I are both using PC's and only my form worked.

    The URL to the form is here: dependableprint.com/oderNEWFORM.php

    It uses an iframe to call on the order form page (the original website where I got this form from said this is ok to do). The form's scripts and pages live here: dependableprint.com/order/index.php (this is the code I pasted in my opening thread).

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    You've got to work on your communication a bit..

    You've posted two completely different URLs. One doesn't exist (even when I added the slash onto the end of /order) and the other does have a form.. but then why supply the first url?

    I have a feeling that this file might be at fault:
    ./include/fgcontactform.php

    Please post it wrapped in [php] tags.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My mistake, I had a typo in the link: http://dependableprint.com/orderNEWFORM.php (but I don't think you need this as you stated).

    The form and all its file are in a folder called "order" here: http://dependableprint.com/order/ or go to http://dependableprint.com/order/index.php

    Here is the code for "fgcontactform.php"

    PHP Code:
    <?PHP
    /*
        Contact Form from HTML Form Guide

        This program is free software published under the
        terms of the GNU Lesser General Public License.

    This program is distributed in the hope that it will
    be useful - WITHOUT ANY WARRANTY; without even the
    implied warranty of MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.

    @copyright html-form-guide.com 2010
    */
    require_once("class.phpmailer.php");

    /*
    Interface to Captcha handler
    */
    class FG_CaptchaHandler
    {
        function 
    Validate() { return false;}
        function 
    GetError(){ return '';}
    }
    /*
    FGContactForm is a general purpose contact form class
    It supports Captcha, HTML Emails, sending emails
    conditionally, File atachments and more.
    */
    class FGContactForm
    {
        var 
    $receipients;
        var 
    $errors;
        var 
    $error_message;
        var 
    $name;
        var 
    $email;
        var 
    $message;
        var 
    $from_address;
        var 
    $form_random_key;
        var 
    $conditional_field;
        var 
    $arr_conditional_receipients;
        var 
    $fileupload_fields;
        var 
    $captcha_handler;

        var 
    $mailer;

        function 
    FGContactForm()
        {
            
    $this->receipients = array();
            
    $this->errors = array();
            
    $this->form_random_key 'HTgsjhartag';
            
    $this->conditional_field='';
            
    $this->arr_conditional_receipients=array();
            
    $this->fileupload_fields=array();

            
    $this->mailer = new PHPMailer();
            
    $this->mailer->CharSet 'utf-8';
        }

        function 
    EnableCaptcha($captcha_handler)
        {
            
    $this->captcha_handler $captcha_handler;
            
    session_start();
        }

        function 
    AddRecipient($email,$name="")
        {
            
    $this->mailer->AddAddress($email,$name);
        }

        function 
    SetFromAddress($from)
        {
            
    $this->from_address $from;
        }
        function 
    SetFormRandomKey($key)
        {
            
    $this->form_random_key $key;
        }
        function 
    GetSpamTrapInputName()
        {
            return 
    'sp'.md5('KHGdnbvsgst'.$this->GetKey());
        }
        function 
    SafeDisplay($value_name)
        {
            if(empty(
    $_POST[$value_name]))
            {
                return
    '';
            }
            return 
    htmlentities($_POST[$value_name]);
        }
        function 
    GetFormIDInputName()
        {
            
    $rand md5('TygshRt'.$this->GetKey());

            
    $rand substr($rand,0,20);
            return 
    'id'.$rand;
        }


        function 
    GetFormIDInputValue()
        {
            return 
    md5('jhgahTsajhg'.$this->GetKey());
        }

        function 
    SetConditionalField($field)
        {
            
    $this->conditional_field $field;
        }
        function 
    AddConditionalReceipent($value,$email)
        {
            
    $this->arr_conditional_receipients[$value] =  $email;
        }

        function 
    AddFileUploadField($file_field_name,$accepted_types,$max_size)
        {

            
    $this->fileupload_fields[] =
                array(
    "name"=>$file_field_name,
                
    "file_types"=>$accepted_types,
                
    "maxsize"=>$max_size);
        }

        function 
    ProcessForm()
        {
            if(!isset(
    $_POST['submitted']))
            {
               return 
    false;
            }
            if(!
    $this->Validate())
            {
                
    $this->error_message implode('<br/>',$this->errors);
                return 
    false;
            }
            
    $this->CollectData();

            
    $ret $this->SendFormSubmission();

            return 
    $ret;
        }

        function 
    RedirectToURL($url)
        {
            
    header("Location: $url");
            exit;
        }

        function 
    GetErrorMessage()
        {
            return 
    $this->error_message;
        }
        function 
    GetSelfScript()
        {
            return 
    htmlentities($_SERVER['PHP_SELF']);
        }

        function 
    GetName()
        {
            return 
    $this->name;
        }
        function 
    GetEmail()
        {
            return 
    $this->email;
        }
        function 
    GetMessage()
        {
            return 
    htmlentities($this->message,ENT_QUOTES,"UTF-8");
        }

    /*--------  Private (Internal) Functions -------- */


        
    function SendFormSubmission()
        {
            
    $this->CollectConditionalReceipients();

            
    $this->mailer->CharSet 'utf-8';
            
            
    $this->mailer->Subject "Contact form submission from $this->name";

            
    $this->mailer->From $this->GetFromAddress();

            
    $this->mailer->FromName $this->name;

            
    $this->mailer->AddReplyTo($this->email);

            
    $message $this->ComposeFormtoEmail();

            
    $textMsg trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
            
    $this->mailer->AltBody = @html_entity_decode($textMsg,ENT_QUOTES,"UTF-8");
            
    $this->mailer->MsgHTML($message);

            
    $this->AttachFiles();

            if(!
    $this->mailer->Send())
            {
                
    $this->add_error("Failed sending email!");
                return 
    false;
            }

            return 
    true;
        }

        function 
    CollectConditionalReceipients()
        {
            if(
    count($this->arr_conditional_receipients)>&&
              !empty(
    $this->conditional_field) &&
              !empty(
    $_POST[$this->conditional_field]))
            {
                foreach(
    $this->arr_conditional_receipients as $condn => $rec)
                {
                    if(
    strcasecmp($condn,$_POST[$this->conditional_field])==&&
                    !empty(
    $rec))
                    {
                        
    $this->AddRecipient($rec);
                    }
                }
            }
        }

        
    /*
        Internal variables, that you donot want to appear in the email
        Add those variables in this array.
        */
        
    function IsInternalVariable($varname)
        {
            
    $arr_interanl_vars = array('scaptcha',
                                
    'submitted',
                                
    $this->GetSpamTrapInputName(),
                                
    $this->GetFormIDInputName()
                                );
            if(
    in_array($varname,$arr_interanl_vars))
            {
                return 
    true;
            }
            return 
    false;
        }

        function 
    FormSubmissionToMail()
        {
            
    $ret_str='';
            foreach(
    $_POST as $key=>$value)
            {
                if(!
    $this->IsInternalVariable($key))
                {
                    
    $value htmlentities($value,ENT_QUOTES,"UTF-8");
                    
    $value nl2br($value);
                    
    $key ucfirst($key);
                    
    $ret_str .= "<div class='label'>$key :</div><div class='value'>$value </div>\n";
                }
            }
            foreach(
    $this->fileupload_fields as $upload_field)
            {
                
    $field_name $upload_field["name"];
                if(!
    $this->IsFileUploaded($field_name))
                {
                    continue;
                }        
                
                
    $filename basename($_FILES[$field_name]['name']);

                
    $ret_str .= "<div class='label'>File upload '$field_name' :</div><div class='value'>$filename </div>\n";
            }
            return 
    $ret_str;
        }

        function 
    ExtraInfoToMail()
        {
            
    $ret_str='';

            
    $ip $_SERVER['REMOTE_ADDR'];
            
    $ret_str "<div class='label'>IP address of the submitter:</div><div class='value'>$ip</div>\n";

            return 
    $ret_str;
        }

        function 
    GetMailStyle()
        {
            
    $retstr "\n<style>".
            
    "body,.label,.value { font-family:Arial,Verdana; } ".
            
    ".label {font-weight:bold; margin-top:5px; font-size:1em; color:#333;} ".
            
    ".value {margin-bottom:15px;font-size:0.8em;padding-left:5px;} ".
            
    "</style>\n";

            return 
    $retstr;
        }
        function 
    GetHTMLHeaderPart()
        {
             
    $retstr '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".
                       
    '<html><head><title></title>'.
                       
    '<meta http-equiv=Content-Type content="text/html; charset=utf-8">';
             
    $retstr .= $this->GetMailStyle();
             
    $retstr .= '</head><body>';
             return 
    $retstr;
        }
        function 
    GetHTMLFooterPart()
        {
            
    $retstr ='</body></html>';
            return 
    $retstr ;
        }
        function 
    ComposeFormtoEmail()
        {
            
    $header $this->GetHTMLHeaderPart();
            
    $formsubmission $this->FormSubmissionToMail();
            
    $extra_info $this->ExtraInfoToMail();
            
    $footer $this->GetHTMLFooterPart();

            
    $message $header."Submission from 'contact us' form:<p>$formsubmission</p><hr/>$extra_info".$footer;

            return 
    $message;
        }

        function 
    AttachFiles()
        {
            foreach(
    $this->fileupload_fields as $upld_field)
            {
                
    $field_name $upld_field["name"];
                if(!
    $this->IsFileUploaded($field_name))
                {
                    continue;
                }
                
                
    $filename =basename($_FILES[$field_name]['name']);

                
    $this->mailer->AddAttachment($_FILES[$field_name]["tmp_name"],$filename);
            }
        }

        function 
    GetFromAddress()
        {
            if(!empty(
    $this->from_address))
            {
                return 
    $this->from_address;
            }

            
    $host $_SERVER['SERVER_NAME'];

            
    $from ="nobody@$host";
            return 
    $from;
        }

        function 
    Validate()
        {
            
    $ret true;
            
    //security validations
            
    if(empty($_POST[$this->GetFormIDInputName()]) ||
              
    $_POST[$this->GetFormIDInputName()] != $this->GetFormIDInputValue() )
            {
                
    //The proper error is not given intentionally
                
    $this->add_error("Automated submission prevention: case 1 failed");
                
    $ret false;
            }

            
    //This is a hidden input field. Humans won't fill this field.
            
    if(!empty($_POST[$this->GetSpamTrapInputName()]) )
            {
                
    //The proper error is not given intentionally
                
    $this->add_error("Automated submission prevention: case 2 failed");
                
    $ret false;
            }

            
    //name validations
            
    if(empty($_POST['name']))
            {
                
    $this->add_error("Please provide your name");
                
    $ret false;
            }
            else
            if(
    strlen($_POST['name'])>50)
            {
                
    $this->add_error("Name is too big!");
                
    $ret false;
            }

            
    //email validations
            
    if(empty($_POST['email']))
            {
                
    $this->add_error("Please provide your email address");
                
    $ret false;
            }
            else
            if(
    strlen($_POST['email'])>50)
            {
                
    $this->add_error("Email address is too big!");
                
    $ret false;
            }
            else
            if(!
    $this->validate_email($_POST['email']))
            {
                
    $this->add_error("Please provide a valid email address");
                
    $ret false;
            }

            
    //message validaions
            
    if(strlen($_POST['message'])>2048)
            {
                
    $this->add_error("Message is too big!");
                
    $ret false;
            }

            
    //captcha validaions
            
    if(isset($this->captcha_handler))
            {
                if(!
    $this->captcha_handler->Validate())
                {
                    
    $this->add_error($this->captcha_handler->GetError());
                    
    $ret false;
                }
            }
            
    //file upload validations
            
    if(!empty($this->fileupload_fields))
            {
             if(!
    $this->ValidateFileUploads())
             {
                
    $ret false;
             }
            }
            return 
    $ret;
        }

        function 
    ValidateFileType($field_name,$valid_filetypes)
        {
            
    $ret=true;
            
    $info pathinfo($_FILES[$field_name]['name']);
            
    $extn $info['extension'];
            
    $extn strtolower($extn);

            
    $arr_valid_filetypesexplode(',',$valid_filetypes);
            if(!
    in_array($extn,$arr_valid_filetypes))
            {
                
    $this->add_error("Valid file types are: $valid_filetypes");
                
    $ret=false;
            }
            return 
    $ret;
        }

        function 
    ValidateFileSize($field_name,$max_size)
        {
            
    $size_of_uploaded_file =
                    
    $_FILES[$field_name]["size"]/1024;//size in KBs
            
    if($size_of_uploaded_file $max_size)
            {
                
    $this->add_error("The file is too big. File size should be less than $max_size KB");
                return 
    false;
            }
            return 
    true;
        }

        function 
    IsFileUploaded($field_name)
        {
            if(empty(
    $_FILES[$field_name]['name']))
            {
                return 
    false;
            }
            if(!
    is_uploaded_file($_FILES[$field_name]['tmp_name']))
            {
                return 
    false;
            }
            return 
    true;
        }
        function 
    ValidateFileUploads()
        {
            
    $ret=true;
            foreach(
    $this->fileupload_fields as $upld_field)
            {
                
    $field_name $upld_field["name"];

                
    $valid_filetypes $upld_field["file_types"];
                
                if(!
    $this->IsFileUploaded($field_name))
                {
                    continue;
                }

                if(
    $_FILES[$field_name]["error"] != 0)
                {
                    
    $this->add_error("Error in file upload; Error code:".$_FILES[$field_name]["error"]);
                    
    $ret=false;
                }

                if(!empty(
    $valid_filetypes) &&
                 !
    $this->ValidateFileType($field_name,$valid_filetypes))
                {
                    
    $ret=false;
                }

                if(!empty(
    $upld_field["maxsize"]) &&
                
    $upld_field["maxsize"]>0)
                {
                    if(!
    $this->ValidateFileSize($field_name,$upld_field["maxsize"]))
                    {
                        
    $ret=false;
                    }
                }

            }
            return 
    $ret;
        }

        function 
    StripSlashes($str)
        {
            if(
    get_magic_quotes_gpc())
            {
                
    $str stripslashes($str);
            }
            return 
    $str;
        }
        
    /*
        Sanitize() function removes any potential threat from the
        data submitted. Prevents email injections or any other hacker attempts.
        if $remove_nl is true, newline chracters are removed from the input.
        */
        
    function Sanitize($str,$remove_nl=true)
        {
            
    $str $this->StripSlashes($str);

            if(
    $remove_nl)
            {
                
    $injections = array('/(\n+)/i',
                    
    '/(\r+)/i',
                    
    '/(\t+)/i',
                    
    '/(%0A+)/i',
                    
    '/(%0D+)/i',
                    
    '/(%08+)/i',
                    
    '/(%09+)/i'
                    
    );
                
    $str preg_replace($injections,'',$str);
            }

            return 
    $str;
        }

        
    /*Collects clean data from the $_POST array and keeps in internal variables.*/
        
    function CollectData()
        {
            
    $this->name $this->Sanitize($_POST['name']);
            
    $this->email $this->Sanitize($_POST['email']);

            
    /*newline is OK in the message.*/
            
    $this->message $this->StripSlashes($_POST['message']);
        }

        function 
    add_error($error)
        {
            
    array_push($this->errors,$error);
        }
        function 
    validate_email($email)
        {
            return 
    eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$"$email);
        }

        function 
    GetKey()
        {
            return 
    $this->form_random_key.$_SERVER['SERVER_NAME'].$_SERVER['REMOTE_ADDR'];
        }

    }
    ?>

  • #12
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, the code for "class.phpmailer.php" exceeds the limit and won't allow me to post. If you need to see this code, the file is here: http://dependableprint.com/order/inc....phpmailer.php

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    You would of just been best using PHPMailer directly instead of using a class that uses PHPMailer internally as it's not looking for PHPMailer errors.

    Open PHP mailer, look at line 1471 and show me the code please. I suspect it has something stupid about the phpverion < 6. If it does change it to 5 and do the same a few lines below as this caused me problems recently. The file you're looking for is class.phpmailer.php iirc.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #14
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The lines from 1419-1525 from "class.phpmailer.php" are below, but I don't think they say anything about the version.

    PHP Code:
      /**
       * Encode string to q encoding.
       * @access private
       * @return string
       */
      
    function EncodeQ ($str$position 'text') {
        
    /* There should not be any EOL in the string */
        
    $encoded preg_replace("[\r\n]"''$str);

        switch (
    strtolower($position)) {
          case 
    'phrase':
            
    $encoded preg_replace("/([^A-Za-z0-9!*+\/ -])/e""'='.sprintf('%02X', ord('\\1'))"$encoded);
            break;
          case 
    'comment':
            
    $encoded preg_replace("/([\(\)\"])/e""'='.sprintf('%02X', ord('\\1'))"$encoded);
          case 
    'text':
          default:
            
    /* Replace every high ascii, control =, ? and _ characters */
            
    $encoded preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
                  
    "'='.sprintf('%02X', ord('\\1'))"$encoded);
            break;
        }

        
    /* Replace every spaces to _ (more readable than =20) */
        
    $encoded str_replace(' ''_'$encoded);

        return 
    $encoded;
      }

      
    /**
       * Adds a string or binary attachment (non-filesystem) to the list.
       * This method can be used to attach ascii or binary data,
       * such as a BLOB record from a database.
       * @param string $string String attachment data.
       * @param string $filename Name of the attachment.
       * @param string $encoding File encoding (see $Encoding).
       * @param string $type File extension (MIME) type.
       * @return void
       */
      
    function AddStringAttachment($string$filename$encoding 'base64'$type 'application/octet-stream') {
        
    /* Append to $attachment array */
        
    $cur count($this->attachment);
        
    $this->attachment[$cur][0] = $string;
        
    $this->attachment[$cur][1] = $filename;
        
    $this->attachment[$cur][2] = $filename;
        
    $this->attachment[$cur][3] = $encoding;
        
    $this->attachment[$cur][4] = $type;
        
    $this->attachment[$cur][5] = true// isString
        
    $this->attachment[$cur][6] = 'attachment';
        
    $this->attachment[$cur][7] = 0;
      }

      
    /**
       * Adds an embedded attachment.  This can include images, sounds, and
       * just about any other document.  Make sure to set the $type to an
       * image type.  For JPEG images use "image/jpeg" and for GIF images
       * use "image/gif".
       * @param string $path Path to the attachment.
       * @param string $cid Content ID of the attachment.  Use this to identify
       *        the Id for accessing the image in an HTML form.
       * @param string $name Overrides the attachment name.
       * @param string $encoding File encoding (see $Encoding).
       * @param string $type File extension (MIME) type.
       * @return bool
       */
      
    function AddEmbeddedImage($path$cid$name ''$encoding 'base64'$type 'application/octet-stream') {

        if(!@
    is_file($path)) {
          
    $this->SetError($this->Lang('file_access') . $path);
          return 
    false;
        }

        
    $filename basename($path);
        if(
    $name == '') {
          
    $name $filename;
        }

        
    /* Append to $attachment array */
        
    $cur count($this->attachment);
        
    $this->attachment[$cur][0] = $path;
        
    $this->attachment[$cur][1] = $filename;
        
    $this->attachment[$cur][2] = $name;
        
    $this->attachment[$cur][3] = $encoding;
        
    $this->attachment[$cur][4] = $type;
        
    $this->attachment[$cur][5] = false;
        
    $this->attachment[$cur][6] = 'inline';
        
    $this->attachment[$cur][7] = $cid;

        return 
    true;
      }

      
    /**
       * Returns true if an inline attachment is present.
       * @access private
       * @return bool
       */
      
    function InlineImageExists() {
        
    $result false;
        for(
    $i 0$i count($this->attachment); $i++) {
          if(
    $this->attachment[$i][6] == 'inline') {
            
    $result true;
            break;
          }
        }

        return 
    $result;
      } 
    However, starting on line 1745, there is a long list of mime types. On line 1797 it lists: 'php', 'php3' and 'php4'. I attached the entire file (in TXT format) for you to see in full length.

    If this is too much of a pain, I am absolutely open to using a new formmailer. As long as it has a file attachment field to upload any file format from any computer or browser.

    Thank you!!

  • #15
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If the TXT file didn't attach, you can view the code here in TXT format: http://dependableprint.com/order/inc...r.php_code.txt


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •