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.