Lasso Soft Inc. > Home

  • Tutorials

Sending Email with Lasso

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.

  • Firstly we will set up the form in the web page the user will use to enter the information.
  • Secondly we will add the code you will need to assemble the email and send it.

Contact page setup

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>

 

Processing the submitted form and sending the email

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:

  • 'Host' - the mail server you will be using to send the email (also known as an SMTP server)
  • 'Username' and 'Password' - to send via thie above mail server, you will need an account. Lasso uses these username and password parameters to log into this server and send your email.
  • 'From' address - this is the from email address you wish to display.
  • 'To' address - the email address of the recipient of your email.

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!'

Troubleshooting

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.

Next steps

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.

Types and Methods used in this Tutorial

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

Comments

No comments found
You must be logged in to comment.

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. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft