Hey guys, I've read what feels like a thousand topics on simple email contact forms in October, so please forgive me for another similar post - but I haven't found a solution to this issue anywhere. I'm attempting to set up a contact form by following these steps:
- Create a new form. I've tried adding this directly to a page, and have also tried adding it to a partial, then importing the partial to a page.
<form class="form-contact" data-request="onSend"> <input type="text" name="username" required="required" placeholder="Your Name"> <textarea name="usermessage" placeholder="Message text" required="required"></textarea> <div> <button type="submit">Submit</button> <button type="reset">Reset</button> </div> </form> -
Define the onSend function. I've tried to do this in the Code tab of the Layout, the Code tab of the Page, and even the Code tab of the Partial.
function onSend(){ $name = post('username'); $content = post('usermessage'); $params = compact('name','content'); Mail::sendTo('mytestemail@gmail.com', 'csi.website::mail.contactform', $params); return true; }Note: I'm using a real email, not actually "mytestemail@gmail.com".
-
Configure mail for SMTP via Gmail.
-
Create a mail template with the code "csi.website::mail.contactform".
-
Send a test email from the "csi.website::mail.contactform" template. At this point I receive the email without issues.
- Use the contact form on the live website - I do not receive the email. When I click submit, the
onSend()method seems to be called successfully. I get a loading indicator which then goes away. If I usedata-request-successanddata-request-erroron the form to send alerts, the success alert is always triggered. However, I never receive the email.
Can anyone please help me to understand the issue? It seems strange that the test email works perfectly, but the contact form never works at all. I've also tried going down a different route and writing a custom plugin to contain the onSend() method but I had pretty much exactly the same issue there. Please help!
Last updated