Form to Email How To

Hello Everyone,

I am hoping for some direction here. I have been working on this for 2 days now. I have read everything I can in the forum, Wiki, and watched every video I could find related to forms and email. None of it is really up to date and most of what I found was for 2018.

I have tried this is both 5 latest build and 6 latest beta.

Quick overview of what I am trying to do and the config.
Created a very simple form with 2 input fields and a text area. Name, Email, Comments. Using PHP nothing else but just that form. App\Container\Row\Column\Form\Vertical Form Groups, and then a button
Form1
Method is post and set to Server Connect
Action is set to pull in API
Global Mailer has been set to SMTP and using SSL. User name and pwd verified works so know that is correct
Using the API I imported form and $post values
Set Execute to Send Mail
Set to pull from global mail config
Completed values per steps form to email in wiki
Now I have tried a lot of things and none of them send and email.
For the form currently is is set as above and I have a dynamic event on server connect sucess to submit and then clear the form
I have set the form as default at the moment. Note tired as submit as well
I have set the button now as dynamic event on mouse click to validate the 3 fields and submit and then clear
Nothing is working. Docs are not up to date for even 5

Just trying to determine what I am missing. I have made this very basic at first just to verify this works.
Using PHP with BS5 and own web

What should this config be to work. I know it’s me just missing something. I used to use PHP mail in the past but trying to move to forms.

Any help is greatly appreciated.

Hey @mebroyles01,

You describing what you do but as a matter of fact even if a dot or a letter is missing (or is wrong) this is not working…

Please share your form code and screenshot of your serveraction for better check

<!doctype html>

<link rel="stylesheet" href="dmxAppConnect/dmxValidator/dmxValidator.css" />

<script src="dmxAppConnect/dmxAppConnect.js"></script>

<script src="dmxAppConnect/dmxValidator/dmxValidator.js" defer></script>

<meta name="ac:route" content="/degub">

<base href="/">

<meta charset="UTF-8">

<title>Untitled Document</title>

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous" />

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

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

<link rel="stylesheet" href="css/style.css" />
<div class="container">

    <div class="row">

        <div class="col">

            <form method="post" id="form1" is="dmx-serverconnect-form" action="dmxConnect/api/debugapi.php" dmx-on:success="form1.reset(true)">

                <div class="form-group md-3"> <label for="input1" class="Name">Name</label>

                    <input type="text" class="form-control" id="input1" name="input1" aria-describedby="input1_help" placeholder="Enter Name" required="" data-rule-letterswithbasicpunc="">

                </div>

                <div class="form-group md-3"> <label for="input2" class="form-label">Email</label>

                    <input type="text" class="form-control" id="input2" name="input2" aria-describedby="input1_help" placeholder="Enter Email" required="" data-rule-email="">

                </div>

                <div class="form-group md-3">

                    <label for="input3" class="form-label">Comments</label><textarea id="text1" class="form-control" placeholder="Enter Comments" required=""></textarea>

                </div>

                <div class="form-group md-3">

                    <button id="btn1" class="btn btn-primary w-100" dmx-on:click="input1.validate();input2.validate();text1.validate();form1.submit()">Submit</button>

                </div>

            </form>

        </div>

    </div>

</div>

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

This is a API I created. I am using the mailer under globals.

First of all, you need your button to be a submit button, so set its type to submit. Then you should apply the validation on the inputs directly not on form dynamic events.

I have tried it as a submit button. This config from this video as an attempt to see if it was me.
Links and I haved


Okay I have set the button as submit and removed the dynamic actions. Tested it and it still does the validation just does not clear the form or send the email yet. I appreciate the responses.

Here is how the form is currently

Remove the validation events please and check this:

1 Like

This is very helpful. Three things.
One I did get a 404 error and that was due to the text field being required.
I removed that validation
Now I get the message body is empty.
Attached is what I am using.
BTW I put something in there and tested it and get SMTP error and I will continue to work that as well however; need insight to what I am missing on the text binding.serveraction 10

Okay this debug thing is really helpful Teodor!!!
I set it to server default and just put test in my body to see if the form works and success. Getting way closer now. I am learning so thank you for your patience.
So need to know why text binding is failing on my side. Any other helpful tips there?
Will try to figure out SMTP why it fails.

Okay I updated the text to just say comments for ID and name. I then went to my API and set mail body to:{{$_POST.comments}}
That did it for getting the contents of the text field. Now more tweaking and getting some additional things in place. Any good tips for a redirect that email was sent successful and that someone would contact them within 24 hours and where it should go?

Again thanks to Teodor. For those trying to set this up this should be the first go to as it’s a time saver.

Hey!

On the form properties, use a “succesfull” dynamic event and then (when the api is succesfuly) you can redirect to another page using the browser component (previously added to the page). Or you can set it to open a modal. You can choose.

Ps you can use other events like error/unauthorized/invalid

Okay been doing some digging and nearly have SMTP all setup. Had some additional backend work to do as well.

Now with the debug mode I am now getting connectivity. However; my last part in the response is this error after the SMTP connection and looking for tips and tricks on how to address this. I am still fairly new at web dev and still learning.

The error. I get 200 post in debug and the response tab has this:
Fatal error: Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at /pathtofile/dmxConnectLib/PHPMailer/PHPMailer/SMTP.php:279) in /pathtofile/dmxConnectLib/dmxConnect.php:84 Stack trace: #0 [internal function]: exception_error_handler(2, ‘Cannot modify h…’, ‘/pathto…’, 84, Array) #1 /pathtofile/dmxConnectLib/dmxConnect.php(84): header(‘HTTP/2.0 500 In…’) #2 [internal function]: exception_handler(Object(ErrorException)) #3 {main} thrown in /pathtofile/dmxConnectLib/dmxConnect.php on line 84

Fatal error: Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at /pathtofile/dmxConnectLib/PHPMailer/PHPMailer/SMTP.php:279) in /pathtofile/dmxConnectLib/dmxConnect.php:45 Stack trace: #0 [internal function]: exception_error_handler(2, ‘Cannot modify h…’, ‘/pathto…’, 45, Array) #1 /pathtofile/dmxConnectLib/dmxConnect.php(45): header(‘HTTP/2.0 500 In…’) #2 [internal function]: fatal_handler() #3 {main} thrown in /pathtofile/dmxConnectLib/dmxConnect.php on line 45

Now I did change the path to just for this post. It is not the real path.

Also, I did open up the two files referenced above and looked at the line number content:
header($protocol . ’ 500 Internal Server Error’);

Can you share a screenshot of your Sendmail step and please explain the fields you have assigned there…

Sure. Also, using SMTP for the mail and SSL port 465. That all seems to go okay as far as connecting.

There’s no need to add the ‘setup mailer step’ if you have it under global.

Can you check the project publisher to check if all the files are uploaded to the server? Maybe something is missing.

1 Like

Removed setup and verified files are all present on the web server. Same result. Just not 100% sure which way to go here.