Welcome, Guest. Please login or register.
Did you miss your activation email?
11 May 2008, 20:14

Login with username, password and session length
Home Chat Help Search Calendar Login Register
Pages: [1]
Print
Author Topic: Send An Email from within A Page  (Read 1086 times)
0 Members and 1 Guest are viewing this topic.
calguy1000
Posts that don't follow the rules (don't ask what the rules are, read them) will be ignored, moved or deleted
Dev Team Member
Power Poster
*****

Karma: 141
Offline Offline

Posts: 3456

Location: Calgary, Canada



WWW
« on: 14 Feb 2008, 11:35 »

Here's a simple example of an advanced topic:  Accessing CMSMailer from within your page content.

Here's my code.... for reference:

Code:
{if isset($smarty.post.submit)}
  {cmsmailer} {* udt *}
  {$cmsmailer->reset()}
  {$cmsmailer->SetSubject('Test Message')}
  {$cmsmailer->AddAddress('calguy1000@cmsmadesimple.org')}
  {$cmsmailer->SetBody('This is a test message')}
  {$cmsmailer->Send()}
  Message Sent
{else}
  <form name="test" method="post">
  <input type="submit" name="submit" value="Send Test Message">
  </form>
{/if}

This code creates a simple form with a single submit button on it.  When the button is clicked, the result is returned to the same page, and the smarty logic kicks in.

First the {cmsmailer} udt is invoked which simply assigns the cmsmailer object to smarty for use in our page
Then I call the various cmsmailer methods to send an email.

This example kinds blurs the lines between programming and layout and design, but only a little bit Smiley
I'm sure you can find many uses for code like this to send messages from within your page.

Here's the code for the cmsmailer UDT:
Code:
global $gCms;

$smarty =& $gCms->GetSmarty();
$cmsmailer =& $gCms->modules['CMSMailer']['object'];

$smarty->assign_by_ref('cmsmailer',$cmsmailer);
Logged

----
CMS Made Simple is Simple - For experienced developers.   You don't need to know php to use CMS but you should have some experience with website design, website development, and supporting dynamic applications in a hosted environment.   The words CSS, XHTML, and permissions should not be new to you.
vaughnt
Forum Member
*

Karma: 5
Offline Offline

Posts: 65


WWW
« Reply #1 on: 14 Feb 2008, 11:51 »

that's a good building block, thanks.
Logged

--
My photography: http://vaughnsphotoart.com
Website development: http://iplenus.com
Ecards: http://www.emailideas.com
calguy1000
Posts that don't follow the rules (don't ask what the rules are, read them) will be ignored, moved or deleted
Dev Team Member
Power Poster
*****

Karma: 141
Offline Offline

Posts: 3456

Location: Calgary, Canada



WWW
« Reply #2 on: 14 Feb 2008, 12:02 »

Continuing on the above note.... Here's a simple contact form that uses the udt I created above.  Essentially, the {contact_form} plugin, and the contact_form form in formbuilder are not really needed.

Though this example doesn't have captcha... I'm pretty sure that if I applied myself for a few minutes, I could get that to work in this example too.

Code:
{* a simple contact form writtten entirely in smarty *}

{if isset($smarty.post.submit)}
   {* process the form *}
   {if empty($smarty.post.name)}
        <p><font color="red">Error: You must specify A name</font></p>
   {elseif empty($smarty.post.email)}
        <p><font color="red">Error: You must specify An Email Address</font></p>
   {elseif empty($smarty.post.subject)}
        <p><font color="red">Error: You must specify A message subject</font></p>
   {elseif empty($smarty.post.message)}
        <p><font color="red">Error: You must specify A message body</font></p>
   {else}
       {* prepare the message body *}
{capture assign='body'}
Message From: {$smarty.post.name} ({$smarty.post.email})
Message Sent:  {$smarty.now|cms_date_format}
Message Text:
-------------------
{$smarty.post.message}
{/capture}

       {* send it *}
       {cmsmailer}
       {$cmsmailer->reset()}
       {$cmsmailer->AddAddress('calguy1000@cmsmadesimple.org')}
       {$cmsmailer->SetSubject($smarty.post.subject)}
       {$cmsmailer->SetBody($body)}
       {capture assign='junk'}{$cmsmailer->Send()}{/capture}
   {/if}
{/if}

   {* display the form *}
<form name="contactform" method="post">
<table>
   <tr>
      <td>Your Name:</td>
      <td><input name="name" type="text" size="50" maxlength="50"></td>
   </tr>
   <tr>
      <td>Your Email Address:</td>
      <td><input name="email" type="text" size="50" maxlength="50"></td>
   </tr>
   <tr>
      <td>Subject:</td>
      <td><input name="subject" type="text" size="50" maxlength="50"></td>
   </tr>
   <tr>
      <td>Mesage:</td>
      <td><textarea name="message" cols="50" rows="8">Enter Your Message Here</textarea></td>
   </tr>
   <tr>
      <td>&nbsp;</td>
      <td><input name="submit" type="submit" value="Send It"></td>
   </tr>
</table>
</form>

Edit:  I cleaned up the code a bit and did the error checking a bit better.... I also capture the output from the email sending so that it doesn't get output to the page....
« Last Edit: 18 Feb 2008, 10:12 by calguy1000 » Logged

----
CMS Made Simple is Simple - For experienced developers.   You don't need to know php to use CMS but you should have some experience with website design, website development, and supporting dynamic applications in a hosted environment.   The words CSS, XHTML, and permissions should not be new to you.
pixelita
Forum Member
*

Karma: 0
Offline Offline

Posts: 41

Location: Houston, Texas USA


Life is a shit sandwich; eat it or starve.


WWW
« Reply #3 on: 29 Mar 2008, 22:55 »

Would this be what I'd use for something like "email this page to a friend"?  Because that's what I'm looking for right now. Smiley
Logged

Visit us on the web: http://www.pixelita.com
Custom web design and graphic art
Visit Serbia's biggest and best internet forum: http://www.burek.co.yu
Over half a million members and growing
vaughnt
Forum Member
*

Karma: 5
Offline Offline

Posts: 65


WWW
« Reply #4 on: 31 Mar 2008, 08:14 »

Would this be what I'd use for something like "email this page to a friend"?  Because that's what I'm looking for right now. Smiley

Pixelita-

Try this tag/plugin I made:
http://dev.cmsmadesimple.org/projects/tellafriend

See it in action here:
http://www.vaughnsphotoart.com/index.php?page=bare-feet-on-moss
(the button is under the photo)

The hide/show is not part of the functionality, I added that for my site. But the captcha support is included.
Logged

--
My photography: http://vaughnsphotoart.com
Website development: http://iplenus.com
Ecards: http://www.emailideas.com
Pages: [1]
Print
Jump to: