Forum

Thread tagged as: Problem, Forms

Contact form not sending emails

My Perch form is submitting; I can see the results under Form/Contact/ All responses. The problem is those responses are not being emailed to the email address I have listed in Form Options and under Settings/Email (email test was successful).

Perch: 3.0.10, PHP: 7.0.15, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10), perch_forms (1.8.3)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /hermes/walnaweb08a/b1798/moo.hawaiianwarfarecom/perch
PERCH_CORE: /hermes/walnaweb08a/b1798/moo.hawaiianwarfarecom/perch/core
PERCH_RESFILEPATH: /hermes/walnaweb08a/b1798/moo.hawaiianwarfarecom/perch/resources
Image manipulation: GD
PHP limits: Max upload 20M, Max POST 20M, Memory: 64M, Total max file upload: 20M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
DOCUMENT_ROOT: /home/users/web/b1798/moo.hawaiianwarfarecom
REQUEST_URI: /perch/core/settings/diagnostics/
HTTP_HOST: www.hawaiianwarfare.com

Here is my template:

<div id="wrap-form">

        <perch:form id="contact" method="post" app="perch_forms">

        <perch:error for="all" type="general">
            <div class="alert-error">
                <perch:content id="error" type="textarea" label="General error message" textile="true" editor="markitup" />
            </div><!-- end .alert-error -->
        </perch:error>

        <div class="input">
            <perch:label for="name">Full Name</perch:label>
            <perch:input type="text" id="name" required="true" label="Full Name" />
            <perch:error for="name" type="required"><p class="about-error">Please enter your name.</p></perch:error>
        </div><!-- end .input -->

        <div class="input">
            <perch:label for="email">Email</perch:label>
            <perch:input type="email" id="email" required="true" label="Email" />
            <perch:error for="email" type="required"><p class="about-error">Please enter an email address.</p></perch:error>
            <perch:error for="email" type="format"><p class="about-error">Please enter a valid email address.</p></perch:error>
        </div><!-- end .input -->

        <div class="input">
            <perch:label for="message">Message</perch:label>
            <perch:input type="textarea" id="message" required="true" label="Message" />
            <perch:error for="message" type="required"><p class="about-error">Please tell me how I can help you.</p></perch:error>
        </div><!-- end .input -->

        <div class="submit">
            <perch:input type="submit" id="submit" value="Send Now" />
        </div><!-- end .submit -->


        <perch:success>
            <div class="alert-success">
                <perch:content id="success" type="textarea" label="Thank you message" textile="true" editor="markitup" />
            </div><!-- end .alert-success -->
        </perch:success>

        </perch:form>

        <div id="contactinfo">

        </div><!-- end #contactinfo -->

</div><!-- end #wrap-form-->

And here is the pertinent part of the page code:

<!-- InstanceBeginEditable name="content" -->
<div id="logo-wrap-wrap">
    <div id="logo-wrap">
        <div id="logo"> <img src="../images/logo-white-100.png" alt="Hawaiian Warfare logo"></div><!-- end #logo -->
    </div><!-- end #logo-wrap-->
</div><!-- end #logo-wrap-wrap-->
<div id="main-content">
    <h1>Contact</h1>
    <?php perch_content('Contact Form');?> 
</div><!-- end #main-content -->
<!-- InstanceEndEditable -->

I do have the Forms App installed. My perch/config/apps.php file looks like this: ~~~<?php $apps_list = array( 'content', 'categories', 'perch_forms', ); ~~~

My template is located thusly: perch/templates/content/contact-form.html

I have read in another thread that the template needs to be inside perch/templates/forms. Is this why the form is not sending the responses to the email addresses? I have checked with the server and the server can handle content from PHP. Your help is appreciated!

Kimberly Olmsted

Kimberly Olmsted 0 points

  • 3 years ago

Kimberly,

Have you enabled Debug, then submitted a form to see whats going on? Once you have done this please post the debug output here.

DEBUG: https://docs.grabaperch.com/perch/configuration/debug/

If you have the perch_forms app installed, then it is best to use perch_form() which would then be looking for templates in /perch/templates/forms/...

The Forms app works with the forms capability in Perch to give you an area where form options may be set and responses viewed. You require this app if you are using forms that will be processed by Perch. If you use forms that submit to external scripts then you do not need to install the Forms app.

LINK: https://docs.grabaperch.com/addons/forms/

Hi Robert,

I have enabled DeBug on my local version of this site. Here's the output:

Debug Message - Perch 3.0.10
[1] SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='2b1f4d7538aec4508c7564da53727246' LIMIT 1
UPDATE perch2_users SET userHash='42b097f8c975a9baec3b167e92e0f538' WHERE userID='1'
[18] SELECT settingID, settingValue, userID FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC
[7] SELECT itemValue FROM perch2_menu_items WHERE itemType='app'
[1] SELECT * FROM perch2_content_regions WHERE regionID=30 LIMIT 1
[1] SELECT * FROM perch2_pages WHERE pageID='16' LIMIT 1
Using template: /templates/content/contact-form.html
[1] SELECT * FROM perch2_content_items c WHERE c.regionID=30 AND c.itemRev=3 ORDER BY c.itemOrder ASC
Using template: /templates/content/contact-form.html
[1] SELECT * FROM perch2_content_items c WHERE c.regionID=30 AND c.itemRev=3 ORDER BY c.itemOrder ASC
Using template: /templates/content/contact-form.html
Form not posted or did not validate
[1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1
[2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC
[1] SELECT itemTitle FROM perch2_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1
[1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10
[2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC
File: /core/apps/content/modes/edit.form.post.php
Mode: edit.form
Queries: 14
Memory: 4.4306

After the above test of what I had originally, I made a "forms" folder in the perch/template folder and put a copy of my contact-form.html file there. I think I need to change the

<?php perch_content('Contact Form');?> 

on the contact page to

<?php perch_forms('Contact Form');?>

and then, after saving that file, go into the Admin and select this template copy which is in the template/forms folder. However, choosing that does not seem to be an option from the Contact page/ Region Options -- Template menu. Only the templates stored in the Content folder are showing as choices.

Thanks for your help!

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Is that on the page where the form is, after submitting the form?

<?php perch_forms('Contact Form');?>

is wrong... it should be... perch_form as below, also you need the name of the template, not a region name. LINK: https://docs.grabaperch.com/functions/form/perch-form/

<?php perch_form('contact-form'); ?>

This form will now be available in the Perch Forms app within the perch admin, but it won't show up until you have completed the form once (testing)

Once you submit the initial form, go into admin - Perch Forms, then your form will be there with an options...

For Rachel:

This is the DeBug code from the Admin Contact page, after I have filled out the contact form and submitted it. This is with the ~~~ <?php perch_content('Contact Form');?> ~~~ in place on the Contact page and the html template still located within the "perch/templates/content" folders.

Here is the DeBug code:

Debug Message - Perch 3.0.10
[1] SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='3174be09d874a7801b7f2b4b6b4a79d7' LIMIT 1
UPDATE perch2_users SET userHash='fa961a96b410965f0d5d10dbf6f06135' WHERE userID='1'
[18] SELECT settingID, settingValue, userID FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC
[7] SELECT itemValue FROM perch2_menu_items WHERE itemType='app'
[1] SELECT * FROM perch2_content_regions WHERE regionID=41 LIMIT 1
[1] SELECT * FROM perch2_pages WHERE pageID='16' LIMIT 1
Using template: /templates/content/contact-form.html
[1] SELECT * FROM perch2_content_items c WHERE c.regionID=41 AND c.itemRev=2 ORDER BY c.itemOrder ASC
Using template: /templates/content/contact-form.html
[1] SELECT * FROM perch2_content_items c WHERE c.regionID=41 AND c.itemRev=2 ORDER BY c.itemOrder ASC
Using template: /templates/content/contact-form.html
Form not posted or did not validate
[1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1
[2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC
[1] SELECT itemTitle FROM perch2_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1
[1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10
[2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC
File: /core/apps/content/modes/edit.form.post.php
Mode: edit.form
Queries: 14
Memory: 3.3708
Using template: /templates/content/contact-form.html
Form not posted or did not validate

So there is an error in your form....

Robert:

I am not understanding your direction because the documentation page you sent me to (https://docs.grabaperch.com/functions/form/perch-form/) tells me the following: String "The template to use for this form. Must be inside perch/templates/forms"

That leads me to believe that the folder must be labeled "forms" not "form".

Regardless, I tried to do as you suggested, relabeling the folder within the templates folder "form" and changing the code on the Contact page to ~~~<?php perch_form('contact-form.html'); ?>~~~

When I did that the form disappeared from the Contact page so I could not fill it out and submit it.

I appreciate your patience. Can you restate what you've told me in different words?

I do not know at what point I said to name the directory “form”... I pointed out the method “perch_forms()” was wrong and should be “perch_form()”.

Your form in debug is not posting because you have an error. Either missing a required field or something isn’t formatted correctly. So the form is being returned to the browser with an error.

Thanks Robert. I'm checking the form code now.

I have copied a sample perch form template, saved it as contact-form2.html, saved it in the templates/content folder. I then went to the site, the contact page, and filled out the old form which was still appearing. I then went to the Perch Admin for this site and chose the new template and saved. I went to the site again, filled out the form and submitted. When going into the Admin section again, this is the DeBug message I got:

Debug Message - Perch 3.0.10
[1] SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='355b60f5319e3f2ca6373979b4a28f03' LIMIT 1
UPDATE perch2_users SET userHash='3c0928bbdd287991a8f651d4a11afe5e' WHERE userID='1'
[18] SELECT settingID, settingValue, userID FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC
[7] SELECT itemValue FROM perch2_menu_items WHERE itemType='app'
[1] SELECT * FROM perch2_pages WHERE pageID=16 LIMIT 1
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT * FROM perch2_content_regions WHERE pageID=16 AND regionPage!='*' ORDER BY regionOrder ASC LIMIT 0, 100
[1] SELECT FOUND_ROWS() AS `count`
[1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1
[2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC
[1] SELECT itemTitle FROM perch2_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1
[1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10
[2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC
File: /core/apps/content/modes/page.post.php
[1] SELECT COUNT(*) FROM perch2_content_items WHERE itemJSON!='' AND regionID=41 AND itemRev=3
Queries: 14
Memory: 2.3522

My response showed up in the Admin but I still did not receive an email about this response and this has been the problem from the start.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

What is the debug on the page when you send the form, not the admin, the actual page your form is on after submitting the form.

This is the DeBug message for the Contact page -- in the Perch Admin where the top title is " Editing 'Contact' Page " ~~~ Debug Message - Perch 3.0.10 [1] SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='29750055d38ecc88fc1fdfd3d475bc72' LIMIT 1 UPDATE perch2_users SET userHash='b22022268f16c2e4558ecbc5bc08ac4b' WHERE userID='1' [18] SELECT settingID, settingValue, userID FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC [7] SELECT itemValue FROM perch2_menu_items WHERE itemType='app' [1] SELECT * FROM perch2_pages WHERE pageID=16 LIMIT 1 [1] SELECT SQL_CALC_FOUND_ROWS DISTINCT * FROM perch2_content_regions WHERE pageID=16 AND regionPage!='' ORDER BY regionOrder ASC LIMIT 0, 100 [1] SELECT FOUND_ROWS() AS count [1] SELECT mi., p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1 [2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC [1] SELECT itemTitle FROM perch2_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1 [1] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10 [2] SELECT mi.*, p.privKey FROM perch2_menu_items mi LEFT JOIN perch2_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC File: /core/apps/content/modes/page.post.php [1] SELECT COUNT(*) FROM perch2_content_items WHERE itemJSON!='' AND regionID=41 AND itemRev=3 Queries: 14 Memory: 2.3524~~~

Is this the DeBug message you want? There aren't any debug messages on the actual contact page on the site.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

No, the contact page of the site.

You need to add the line to output the debug as detailed in the original documentation you were sent.

https://docs.grabaperch.com/perch/configuration/debug/

The debug line had already been added to config.php. There is no debug output at the bottom of the site contact page or in the page developer's view of the code. I'm not sure where I would find debug output for an actual page, not a page in Perch admin.

Add this to your site contact page or any other site page to see the debug output

<?php PerchUtil::output_debug(); ?>

Thank you Clive!

Here is the resulting debug output:

Debug Message - Perch 3.0.10
[18] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT * FROM perch2_forms WHERE formKey='contact' LIMIT 1
[1] SELECT * FROM perch2_pages WHERE pagePath='/pages/contact.php' LIMIT 1
Checking Akismet for spam
Message is not spam
Building message with Dollar template
Invalid address: (addAnAddress Reply-To): Kim Olmsted
Using email template: /hermes/walnaweb08a/b1798/moo.hawaiianwarfarecom/perch/core/emails/.txt (txt)
Building message with Dollar template
Invalid address: (addAnAddress Reply-To): Kim Olmsted
Invalid address: (addAnAddress to): Kim Olmsted
INSERT INTO perch2_forms_responses(responseJSON,formID,responseIP,responseSpamData) VALUES('{\"fields\":{\"name\":{\"attributes\":{\"type\":\"text\",\"id\":\"name\",\"required\":\"true\",\"label\":\"Name\"},\"value\":\"Kim Olmsted\"},\"email\":{\"attributes\":{\"type\":\"email\",\"id\":\"email\",\"required\":\"true\",\"label\":\"Email\",\"placeholder\":\"you@company.com\"},\"value\":\"kho@gci.net\"},\"message\":{\"attributes\":{\"type\":\"textarea\",\"id\":\"message\",\"required\":\"true\",\"label\":\"Message\"},\"value\":\"Test 11.11.2017 7:32AM\"}},\"files\":[],\"page\":{\"id\":\"16\",\"title\":\"Contact\",\"path\":\"\\/pages\\/contact.php\",\"navtext\":\"Contact\"}}','1','72.42.145.48','{\"fields\":[],\"environment\":{\"PATH\":\"\\/usr\\/local\\/bin:\\/usr\\/bin:\\/bin\",\"SCRIPT_NAME\":\"\\/pages\\/contact.php\",\"REQUEST_METHOD\":\"POST\",\"HTTP_ACCEPT\":\"text\\/html,application\\/xhtml+xml,application\\/xml;q=0.9,*\\/*;q=0.8\",\"SCRIPT_FILENAME\":\"\\/home\\/users\\/web\\/b1798\\/moo.hawaiianwarfarecom\\/pages\\/contact.php\",\"HTTP_ORIGIN\":\"https:\\/\\/www.hawaiianwarfare.com\",\"SERVER_SOFTWARE\":\"Apache\\/2\",\"REMOTE_PORT\":\"65091\",\"HTTP_USER_AGENT\":\"Mozilla\\/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit\\/601.7.8 (KHTML, like Gecko) Version\\/9.1.3 Safari\\/537.86.7\",\"HTTP_ACCEPT_LANGUAGE\":\"en-us\",\"CONTENT_TYPE\":\"application\\/x-www-form-urlencoded\",\"GATEWAY_INTERFACE\":\"CGI\\/1.1\",\"SCRIPT_URL\":\"\\/pages\\/contact.php\",\"DOCUMENT_ROOT\":\"\\/home\\/users\\/web\\/b1798\\/moo.hawaiianwarfarecom\",\"UNIQUE_ID\":\"WgcmGgoBcBsAAFHhnh8AAAAA\",\"SERVER_NAME\":\"www.hawaiianwarfare.com\",\"HTTP_REFERER\":\"https:\\/\\/www.hawaiianwarfare.com\\/pages\\/contact.php\",\"SERVER_ADMIN\":\"cgiadmin@yourhostingaccount.com\",\"HTTP_ACCEPT_ENCODING\":\"gzip, deflate\",\"HTTP_CONNECTION\":\"keep-alive\",\"CONTENT_LENGTH\":\"185\",\"SCRIPT_URI\":\"https:\\/\\/www.hawaiianwarfare.com\\/pages\\/contact.php\",\"SERVER_PORT\":\"80\",\"HTTP_COOKIE\":\"cmsa=1; PHPSESSID=8ebc222ae31c38fe2d9f316b40197293\",\"REMOTE_ADDR\":\"72.42.145.48\",\"SERVER_PROTOCOL\":\"HTTP\\/1.1\",\"REQUEST_URI\":\"\\/pages\\/contact.php\",\"HTTP_HOST\":\"www.hawaiianwarfare.com\",\"TZ\":\"EST5EDT\",\"PHP_SELF\":\"\\/pages\\/contact.php\",\"REQUEST_TIME_FLOAT\":1510417946.4796,\"REQUEST_TIME\":1510417946,\"argv\":[],\"argc\":0}}')
[1] SELECT * FROM perch2_forms_responses WHERE responseID='15' LIMIT 1
No ids to log.
Array
(
    [type] => 8
    [message] => Undefined index: body
    [file] => /hermes/walnaweb08a/b1798/moo.hawaiianwarfarecom/perch/addons/apps/perch_forms/PerchForms_Akismet.class.php
    [line] => 49
)

I don't understand why it is saying the email address is invalid. I've checked the email in Settings/Email. The test worked fine and the email came through. I have listed two email addresses on the Admin Editing Forms/Form Options page, both have tested fine and they are separated by a comma only, no spaces.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The string "Kim Olmsted" is not an email address. Check that you have an email address, not a name in the settings.

https://docs.grabaperch.com/addons/forms/installation/

I have found the error:

On the Editing Forms/Form Option page I had not sleeked "email" under the "Email Address Field". Everything is now working.

Thank you Rachel, Robert, and Clive.

Argh. I spoke too soon.

I am now getting an email as the responder -- affirming that my email has been sent to the site owner.

I am not receiving an email as the site owner would, informing me of a response.