This tutorial outlines how to assemble the information required to send an email with Lasso 9 in response to a contact form on a website.
Below is an example HTML form on a "Contact Us" page that a user would use to enter their information. On submit of the form, a response page (conveniently named "response.lasso") is loaded which processes the form and sends the email.
<form action="response.lasso" method="post">
Your Name: <input type="text" name="yourName" value="" /><br />
Your Email: <input type="text" name="yourEmail" value="" /><br />
Your Comment: <textarea name="yourComment"></textarea><br />
<input type="submit" name="submit" value="submit" />
</form>
This section describes the code on the response page, "response.lasso".
The form parameters from the HTML form are accessible to Lasso via the [action_param( ... )] method.
For example, to see what the user entered in the form, one could use the following code:
Name entered was: [action_param('yourName')]<br />
Email entered was: [action_param('yourEmail')]<br />
Comment entered was: [action_param('yourComment')]
To send an email you will need the following information:
The 'Subject' and 'Body' parameters of the email are also needed to successfully send an email, but we are going to customize these.
In the following code we are going to assemble the subject and body, then send the email, and output a "thank you" message.
local(subject = 'A new contact received from our website: ' + action_param('yourName'))
local(body = 'Contact received on: '+date+'\r')
#body += 'Contact name: '+action_param('yourName')+'\r'
#body += 'Contact email: '+action_param('yourEmail')+'\r\r'
#body += 'Comment: \r'+action_param('yourComment')+'\r\r'
#body += 'Contact recieved from IP Address: '+(web_request->remoteAddr)
email_send(
-host = 'mail.example.com',
-username = 'myMailAccount',
-password = 'myMailAccountPassword',
-from = 'myMailAccount@example.com',
-to = 'recipient@example.com',
-subject = #subject,
-body = #body
)
'Thank you '+action_param('yourName')+', we will be in touch soon!'
If you are experiencing difficulties with sending the email, there are a few to consider:
[Action_Param] values are not accessible inside inline blocks.
If you have wrapped your code inside an [inline] ... [/inline] Lasso will not return your GET or POST parameters. You will need to either set them as variables before the first [inline] statement or install and use the [client_param] method. The [client_param] methods are not part of the core Lasso 9 distribution and can be obtained from TagSwap, an open source Lasso code repository.
Email Authentication
One of the common problems with sending emails is authenticating with the sending SMTP mail server. If no error is reported in the sending script and the email has not beed received after a reasonable length of time, it is likely that the email has been queued by Lasso but the athentication credentials are not being accepted by the specified remote server.
To check this, visit the Lasso 9 administration console (http://yourserver.com/lasso9/Admin/) and view the email queue. If your email is still present in the queue it will display an error message outlining the reason it has been unable to send. Common causes for email sending failures include authentication failures, SMTP relay restrictions at the remote server, TCP/IP Port restrictions in corporate or ISP firewalls.
Any successful online "contact us" form should have validation and protection from spammers & "bots". This is not covered in this tutorial however we will be covering these topics in future tutorials and articles.
More detail on the types and methods used in this tutorial can be found by visiting the following links:
Next Tutorial: Understanding Cookies and Sessions
Author: Jonathan Guthrie
Created: 26 Feb 2011
Last Modified: 17 Mar 2011
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft