Contact form, configuration from start to finish

Hello Friends, I need the help of a master, so that I can understand how the contact form works, the fields I have to fill and the libraries with direct calls by CDN, I’m using PHP, I can’t make it work by the form. estou usando bootstrap.

<?php /** * Requires the PHP Mail Form library * The PHP Mail Form library is available only in the pro version of the template * The library should be uploaded to: lib/php-mail-form/php-mail-form.php * For more info and help: https://templatemag.com/php-mail-form/ */ if( file_exists($php_mail_form_library = '../lib/php-mail-form/php-mail-form.php' )) { include( $php_mail_form_library ); } else { die( 'Unable to load the PHP Mail Form Library!'); } $contactform = new PHP_Mail_Form; $contactform->ajax = true; // Replace with your real receiving email address $contactform->to = '**contato@example.com**'; $contactform->from_name = $_POST['name']; $contactform->from_email = $_POST['email']; $contactform->subject = $_POST['subject']; $contactform->add_message( $_POST['name'], 'From'); $contactform->add_message( $_POST['email'], 'Email'); $contactform->add_message( $_POST['message'], 'Message', 10); echo $contactform->send(); ?>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<?php /** * PHP Mail Form * Version: 2.0 * Website: https://templatemag.com/php-mail-form/ * Copyright: TemplateMag.com */ class PHP_Mail_Form { public $to = false; public $from_name = false; public $from_email = false; public $subject = false; public $mailer = false; public $message = ''; public $content_type = 'text/html'; public $charset = 'UTF-8'; public $ajax = false; public $error_msg = array( 'invalid_to_email' => 'Email to: is empty or invalid!', 'invalid_from_name' => 'From Name is empty!', 'invalid_from_email' => 'Email from: is empty or invalid!', 'invalid_subject' => 'Subject is too short or empty!', 'invalid_mailer' => 'Mailer Email is empty or invalid!', 'short' => 'is too short or empty!', 'send_error' => 'Could not send mail! Please check your PHP mail configurations.', 'ajax_error' => 'Sorry, the request should be an Ajax POST', ); private $error = false; public function __construct() { $this->mailer = "formsubmit@" . @preg_replace('/^www\./','', $_SERVER['SERVER_NAME']); } public function add_message($content, $label = '', $length_check = false) { $message = filter_var($content, FILTER_SANITIZE_STRING) . '
'; if( $length_check ) { if( strlen($message) < $length_check + 4 ) { $this->error .= $label . ' ' . $this->error_msg['short'] . '
'; return; } } $this->message .= !empty( $label ) ? '' . $label . ': ' . $message : $message; } public function send() { if( $this->ajax ) { if( !isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { return $this->error_msg['ajax_error']; } } $to = filter_var( $this->to, FILTER_VALIDATE_EMAIL); $from_name = filter_var( $this->from_name, FILTER_SANITIZE_STRING); $from_email = filter_var( $this->from_email, FILTER_VALIDATE_EMAIL); $subject = filter_var( $this->subject, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); $mailer = filter_var( $this->mailer, FILTER_VALIDATE_EMAIL); $message = nl2br($this->message); if( ! $to || $to = 'contato@example.com') $this->error .= $this->error_msg['invalid_to_email'] . '
'; if( ! $from_name ) $this->error .= $this->error_msg['invalid_from_name'] . '
'; if( ! $from_email ) $this->error .= $this->error_msg['invalid_from_email'] . '
'; if( ! $subject ) $this->error .= $this->error_msg['invalid_subject'] . '
'; if( ! $mailer) $this->error .= $this->error_msg['invalid_mailer'] . '
'; if( $this->error ) { return $this->error; } $headers = 'From: ' . $from_name . ' <' . $mailer . '>' . PHP_EOL; $headers .= 'Reply-To: ' . $from_email . PHP_EOL; $headers .= 'MIME-Version: 1.0' . PHP_EOL; $headers .= 'Content-Type: ' . $this->content_type . '; charset=' . $this->charset . PHP_EOL; $headers .= 'X-Mailer: PHP/' . phpversion() . ' with PHP_Mail_Form'; $sendemail = mail($to, $subject, $message, $headers); if( $sendemail ) { return 'OK'; } else { return $this->error_msg['send_error']; } } } ?>

/////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html>

< html lang = "en" >

< head >

< meta charset = "utf-8" >

< title >My Page</ title >

< link href = "/bootstrap/css/bootstrap-combined.min.css" rel = "stylesheet" >

< link href = "bootstrap/css/bootstrap-responsive.min.css" rel = "stylesheet" >

< link href = "css/my-stylesheet.css" rel = "stylesheet" >

</ head >

< body >

< div class = "container" >

</ div > <!-- /container -->

< script src = "js/jquery.min.js" ></ script >

< script src = "bootstrap/js/bootstrap.min.js" ></ script >

< script src = "js/my-javascript.js" ></ script >

</ body >

</ html >
/////////////////////////////////////////////////////////////////////

Hello there @Lucena, do you have the Pro version of this Bootstrap template? As it says this form will only work with these,

if so, do you become a member by buying their template, in which case have you asked for support here?
https://templatemag.com/members/?nav=support

…or are you just playing with the PHP form code, trying to get it to work on your own?
PS, alas, I too am not. a master :slight_smile:

1 Like

From my earliest dabbling in web design, I have always hated trying to implement forms on websites. I discovered jotform.com around 2009, when they were still a fledgling company, and didn’t charge their rather exorbitant current rates.

As a result, I got “grandfathered” in at their early business rate which includes unlimited forms, and is (ridiculously) only a fraction of what they now charge for their unlimited plan. According to their website, I will stay at this price as long as I remain with them which, if true, is a real steal, so I’m not holding my breath. But I’ll be really upset if I lose it, because it’s saving me hundreds of dollars a year.

In any case, there are other form companies out there that you can look into that can save you the aggravation of dealing with PHP, CDNs and so on.

1 Like

I have two favorite ways of working with forms.

Post the data to a flatfile, database, or another server.
Send the data off to MailChimp, AWeber, or Paypal.

My least fave is having to deal with PHPMail and SMTP.

1 Like

Hi Lucena,

I would go for this script:
https://codecanyon.net/item/quform-responsive-ajax-contact-form/148273

You get excellent support from Al and Ally who implemented PHP mailer is this script including designs and every element you need in a form.

Regards,
David

2 Likes

Ah, thank you… stir the pot a little bit, and you never know what you will find! I think I like this answer the best. Ima have to check into this. Thanks!

(besides $9… I’ll just go rob my piggy-bank, but I’ll have to do it when it’s raining :umbrella:)

2 Likes

Yes I have the version Web Editor - 5.8 PRO WordPress Personal, updated and still bought some Templates with Template Mag, which left me in hand, did not support me. I contacted two times nor returned my questions. In Pinegrow, although I paid for the PRO version, they didn’t help much either, they just want to sell anything else. The only help I got was here at the Forum with you who had the good will, trying to help and so thank you all. But I’m having a hard time with Pinegrow, using some features is not in my native language which makes it more difficult, until the moment I could not complete any site completely.
It discouraged me a little, I expected a better program with more ease to use, many explanatory documents are old versions that no longer work today the tutorial is outdated.
What led me to get Pinegrow was the fact that the code is free and not proprietary, but the difficulty is very great.
I think I’ll be coming back to the WebSite X5 always yive good support and the program is in my native language, bad is the code is proprietary, but the current versions are very practical and easy to use, super easy to create forms, thing that here in pinegrow is almost impossible, someone has a code ready working, I believe not, nor the models I bought work or I can not.
But thank you all the friends who helped and even those who tried, thank you very much.

Hi Lucena,

HTML, CSS, PHP, ASP and JavaScript are all based on the English language. So I think you have to study those to be able to really understand what you are doing.

Pinegrow can spit out a form if you want (just make a Bootstrap 4 snippet of a form), but this is useless without a decent PHP script. You can’t expect a editor to create a complete working form system (or you should use a special plugin for it that I have never seen for Pinegrow).

That’s why I gave you the link for the form script that I know and can guaranty excellent support with it. It cost peanuts.

Real web design is never easy when you want to do it professional and comes with a decent study of all disciplines that are needed to accomplish a website.

All coding is in English I’m afraid.

Regards,

David

There is also Jotforms to play with.
They have a free account with limited traffic to start to play around with, to get the ball rolling.

oops forgot the link!