Need help with contact page

Hi. Noob here. :smiley: I have zero knowledge of PHP but I am starting to think my current problems are related to PHP, or the server permissions on my website. I checked everything I know and am having problems getting a contact form to work. I have downloaded and tried about 8 different forms from different places and they all fail the same way. I have a recaptcha contact form and the keys installed and the form comes up just fine and the captcha works. But when I hit the send button it says “sending” but never finishes. I tried some simpler implementations with just captcha and then the image won’t load. The site I am getting the contact form from is here:
http://reusableforms.com/d/b/php-contact-form-with-validation-and-recaptcha

Can someone look at the php code and see if it is ok? I ran some through the PHPTESTER and it fails.
http://phptester.net/

I am just trying to see if it is a problem on my website configuration or a php issue.
Thanks,
NARS

Error:
FATAL ERROR syntax error, unexpected ‘“DIR not allowed”’ (T_CONSTANT_ENCAPSED_STRING) on line number 28

There is no DIR in the code you linked to. You need to add more info. Line number 28 of what file?

I’d really just recommend making this yourself. Adding in composer, javascript handling, etc is just convoluting the process and making it more complex than necessary for your first dabblings with PHP

Thanks for your reply. I really think my problem is more about permissions or something I need to config on my server. I tried about 15 different contact forms and they all generate the same error on my cPanel error log. I have all the permissions set to 644 and 755 so that seems correct. I am fairly new to Linux server admin so I am thinking I have to learn how to edit the htaccess file or something like that. Anyhow, here are the error messages just so you can see what I am up against.
Thanks,
NARS

[code][Mon Feb 12 09:57:21.205979 2018] [cgid:error] [pid 3465:tid 140259035641600] [client xxxxxxx] AH01271: exec used but not allowed in /home/mysite/public_html/500.shtml, referer: http://www.mysite.com/formtester/test.html

[Mon Feb 12 09:57:21.204242 2018] [:error] [pid 3465:tid 140259035641600] [client xxxxxxx] SoftException in Application.cpp:388: UID of script “/home/mysite/public_html/formtester/html_form_send.php” is smaller than min_uid, referer: http://www.mysite.com/formtester/test.html[/code]

What is the actual code you are attempting?

exec used but not allowed in

Is rather explicit, and not something you want.

That tutorial is crap for it uses libraries on libraries, it doesn’t show how or instructs you how to do it.

I have repository that might help you setup a contact page at https://github.com/Strider64/Website-Development

Here’s my contact form (contact.php)
[php]<?php
require ‘config/config.php’;
use Library\Calendar\Calendar;
use Library\Database\Database as DB;
use Library\CMS\CMS;
use Library\Email\Email;
$db = DB::getInstance();
$pdo = $db->getConnection();
$myCalendar = new Calendar();
$myCalendar->phpDate();
$submit = filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($submit) && $submit === ‘submit’) {
/* The Following to get response back from Google recaptcah /
$url = “https://www.google.com/recaptcha/api/siteverify”;
$remoteServer = filter_input(INPUT_SERVER, ‘REMOTE_ADDR’, FILTER_SANITIZE_URL);
$response = file_get_contents($url . “?secret=” . PRIVATE_KEY . “&response=” . \htmlspecialchars($_POST[‘g-recaptcha-response’]) . “&remoteip=” . $remoteServer);
$recaptcha_data = json_decode($response);
/
The actual check of the recaptcha */
if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) {
$data[‘name’] = filter_input(INPUT_POST, ‘name’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘email’] = filter_input(INPUT_POST, ‘email’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘phone’] = filter_input(INPUT_POST, ‘phone’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘website’] = filter_input(INPUT_POST, ‘website’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘reason’] = filter_input(INPUT_POST, ‘reason’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘comments’] = filter_input(INPUT_POST, ‘comments’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$send = new Email($data, $transport);
} else {
$success = “You’re not a human!”;
}
}
require ‘includes/header.inc.php’;
?>

    <fieldset>

        <legend><?php echo (isset($success)) ? $success : 'Contact Form'; ?></legend>

        <label for="name" accesskey="U">Name</label>
        <input name="name" type="text" id="name" tabindex="1" autofocus required="required" />

        <label for="email" accesskey="E">Email</label>
        <input name="email" type="email" id="email" tabindex="2" required="required" />

        <label for="phone" accesskey="P" tabindex="3">Phone <small>(optional)</small></label>
        <input name="phone" type="tel" id="phone">

        <label for="website" accesskey="W" tabindex="4">Website <small>(optional)</small></label>
        <input name="website" type="text" id="website">

        <div class="radioBlock">
            <input type="radio" id="radio1" name="reason" value="message" tabindex="5" checked>
            <label class="radioStyle" for="radio1">message</label>
            <input type="radio" id="radio2" name="reason" value="order">
            <label class="radioStyle" for="radio2">order</label>  
            <input type="radio" id="radio3" name="reason" value="status">
            <label class="radioStyle" for="radio3">status inquiry</label>    
        </div>

        <label class="textBox" for="comments">Comments</label>
        <textarea name="comments" id="comments" spellcheck="true" tabindex="6" required="required"></textarea> 
        <div class="g-recaptcha" data-sitekey="Your_Key"></div>
        <input type="submit" name="submit" value="submit" tabindex="7">
    </fieldset>



</form>
<?php require 'includes/footer.inc.php';[/php]

I give a brief explanation on how to setup namespaces using composer and I use Swiftmailer as my email transport for I don’t want to write my own, plus I find it easier. Have any questions if you choose to use this just email me.

After I reread your problem, Google recaptcha won’t let you test the email portion on a local server if you don’t define the local server on Google’s website. What I did once I get the email portion then I transfer it to my remote server and test it from there, I even knock off the local test server on Google so that I can stylize it with CSS. Here’s my contact page -> https://www.pepster.com/contact though I have to improve my validation portion of the script.

I have tried all kinds and even the simplest fail. I think I may be onto something though. I will post it at the end of the replies here.
Thanks,
NARS

:slight_smile: I think you are correct in that the tutorial is crap. I looked into all the libraries and thought “it has to be easier than all of that”. I appreciate the link and I will go study it and see what I can learn. I actually can get the Google recaptcha to work but the sending is where it fails with an error. I am testing it all on my FPS. Of course I have only 3 weeks VPS experience so I am a noob in that department…but I did run stuff on the shared server for many years. Used Joomla till it got hacked a month ago and am going back to HTML5 and CSS for now. Just need a working contact form or two.
Thanks,
NARS

added: see next post.

Ok, so after fighting this issue for 4 days and being a noob at some of this stuff, I found a php command that I could put into a file and upload to my server to test my php version. I tried it and I get the error message:
[an error occurred while processing this directive]

So I do some more digging and find another version of the same with added info and try it and get the same error. This is a Linux server I am renting for my VPS. Here is the code:

[php]<?php
phpinfo();
?>[/php]

and

[php]<?php
echo 'Current PHP version: ’ . phpversion();
?>[/php]

So I am thinking I have a permission problem right? Or do these tests not always work?
Thanks,
NARS

Does this work?

[php]<?php
echo ‘hello world’;[/php]

If not then if nothing else it has been a good lesson, start as simple as possible when debugging. And make sure your environment actually works before wasting days trying to fix it.

Btw, you should always develop your sites/apps locally. You can use finished web server setups as xampp/wamp, vagrant, docker etc to run a full fledged php/web/db server on your own computer.

Hi Jim,
Well, after trying a bunch of versions of the php command to see what version etc…I called my ISP (for the hundredth time) and told them I am pretty sure all my problems are due to a permission issue and that I hadn’t changed any permissions to cause it. I had them try to run the php cammoand and then they said “oh, I see what you are saying”. :-X So the guy ran some BASH command that rest my permissions and it works now. Of course it would be nice to know what permission was added or enabled but I am just glad that it’s fixed. I made backups of the website right away so I have a good copy for future issues.
Speaking of xampp I just downloaded that yesterday and was going to mess with it today. I have used it many years ago for Joomla site testing. I haven’t tested the contact forms yet but I am pretty sure they will all work now. Great learing experience though and as a VPS noob I did at least figure out it had something to do with my php not working. ;D
Thanks,
NARS

added: Which is best for running on Windows and testing stuff for a Linux VPS?? xampp, wampp, vagrant or docker??

XAMPP and WAMP do the same things. Docker and Vagrant are different animals altogether. They are a good route to go, but have a different learning curve. I encourage you to read up on them individually to see if that is how you want to move going forward.

Ok, thanks for the info. I think I will stick with XAMPP for now as I have used it in the past. What I don’t need right now is any more “learning curves” as I have a bunch of those going on at the moment. ;D
NARS

Sponsor our Newsletter | Privacy Policy | Terms of Service