Website:Emails

From MatureAsskickers Wiki

Jump to: navigation, search

« Home

Contents

Form Mail

The form mailer uses Smarty to generate emails. The logic layer uses the HTTP POST request variables submitted from the form to populate the Smarty variables within the template. Emails can only be sent to recruits, users, and/or groups, that are not expired, and have an email address.

The Template

A template looks like this

Subject: A sample email
Content-Type: text/plain
Charset: iso-9959-1
Attachment: me.jpg

Hello {$name},
Here is a picture of me!

Subject

The subject of the email message can be defined within the template. There must be at least one line starting with Subject: or the subject of No Subject will be used instead. If the Subject is defined more than once, the first instance is used. There must not be any whitespace at the beginning of the line and any carriage-return's '\r\, new-lines '\n', or tab-spaces '\t' are ignored. Smarty variables cannot be used.

Content-Type

The content-type of the email message can be defined within the template. There must be at least one line starting with Content-Type: or the content-type of text/plain will be used instead. If the content-type is defined more than once, the last instance is used. There must not be any whitespace at the beginning of the line and any carriage-return's '\r\, new-lines '\n', or tab-spaces '\t' are ignored. Smarty variables cannot be used.

Charset

The charset of the email message can be defined within the template. There must be at least one line starting with Charset: or the charset of utf-8 will be used instead. If the charset is defined more than once, the last instance is used. There must not be any whitespace at the beginning of the line and any carriage-return's '\r\, new-lines '\n', or tab-spaces '\t' are ignored. Smarty variables cannot be used.

Attachments

Attachement's can be defined within the the template. Several attachments can be made for every line starting with Attachment:. Only one attachment can be made for each line, and the file must reside within the templates/emails/attachments directory. There must not be any whitespace at the beginning of the line and any carriage-return's '\r\, new-lines '\n', or tab-spaces '\t' are ignored. Smarty variables cannot be used.

HTTP POST

The following HTTP POST variable is used to determine the template used for the email.

  • _template - the name of the template without the .tpl extension. A value of mymessage uses the mymessage.tpl template. The application will search in the local /templates/emails/ directory first and if no template is found it will search in the global /templates/emails/ directory. If the template does not exist is either directory the email is ignored.
<input type="hidden" name="_template" value="mymessage">

The following HTTP POST variables are used to determine the repient(s) of the email.

  • recruitid - a singe recruitid, a CVS (comma separated list) or array of recruitid's.
<input type="hidden" name="recruitid" value="1">

<input type="hidden" name="recruitid" value="1,2,3">
<input type="hidden" name="recruitid[]" value="1"> <input type="hidden" name="recruitid[]" value="2"> <input type="hidden" name="recruitid[]" value="3">
  • userid - a singe userid, a CVS (comma separated list) or array of userid's.
<input type="hidden" name="userid" value="1">

<input type="hidden" name="userid" value="1,2,3">
<input type="hidden" name="userid[]" value="1"> <input type="hidden" name="userid[]" value="2"> <input type="hidden" name="userid[]" value="3">
  • groupid - a singe groupid, a CVS (comma separated list) or array of groupid's.
<input type="hidden" name="groupid" value="1">

<input type="hidden" name="groupid" value="1,2,3">
<input type="hidden" name="groupid[]" value="1"> <input type="hidden" name="groupid[]" value="2"> <input type="hidden" name="groupid[]" value="3">

All HTTP POST variables are available to the Smarty template as the input field name (key) from the HTTP POST form.

A simple example

Here is a simple example of a form and a template.

sendmail.html - The HTTP POST form

 <form action="/xml/httppost.xml" method="post">
   <input type="hidden" name="_action[]" value="_email">
   <input type="hidden" name="_template" value="simple">
 
to:<select name="userid"> <option value="1">user 1</option> <option value="2">user 2</option> <option value="3">user 3</option> </select> firstname: <input type="text" name="firstname" value="John"> lastname: <input type="text" name="lastname" value="Doe">
<input type="submit"> </form>

/templates/emails/simple.tpl - The Smarty template

Subject: A simple email
Content-Type: text/plain
Charset: iso-9959-1

Hello {$firstname} {$lastname}!

The email

 Hello John Doe!

A better example

This is a better example using some advanced features.

bettermail.html - The HTTP POST form

 <form action="/xml/httppost.xml" method="post">
   <input type="hidden" name="_action[]" value="_email">
   <input type="hidden" name="_template" value="better">
 
<input type="hidden" name="userid" value="1"> <input type="hidden" name="recruitid" value="1"> to:<select name="groupid[]" size="3" multiple> <option value="1">group 1</option> <option value="2">group 2</option> <option value="3">group 3</option> </select> pick a color:<select name="color"> <option value="red">Red</option> <option value="blue">Blue</option> </select> firstname: <input type="text" name="firstname" value="John"> lastname: <input type="text" name="lastname" value="Doe">
<input type="hidden" name="extra1" value="foo"> <input type="hidden" name="extra2" value="{$extra1}bar"> <input type="submit"> </form>

/templates/emails/better.tpl - The Smarty template

Subject: A better email
Content-Type: text/plain
Charset: iso-9959-1
Attachment: me.jpg
Attachment: fatelvismom.jpg

Hello {$firstname} {$lastname},
I like the color {if $color EQ 'red'}red{else}blue{/if} too.
I've attached a photo of Me with FatElvis's mom!
Regards,
{$extra2}

The email

 Hello John Doe,
 
I like the color red too.
I've attached a photo of Me with FatElvis's mom!
Regards,
{$extra1}bar

Notice

  • The email was sent to a single user, a single recruit and several groups which were submitted as an array of groupid's.
  • Smarty variables are not permitted with values from the form, only in the template. The value of {$extra1}bar will not get translated to foobar as expected.
Personal tools