Skip to main content
Known Participant
February 23, 2012
Question

Converting a small php mail app to a cf mail app, is it possible?

  • February 23, 2012
  • 1 reply
  • 902 views

Hello;

I am trying to use a small app I picked up and it uses a php email tag in a java scrip / jquery based email applet for a web site. The php tag sends a callback to the jquery when the message is sent, if it doesn't, the jquery throws an error and tells the user nothing was sent. I know how to use a cfmail tag, but I am looking for help with sending the callback to the jquery.

I'm posting both sets of code, the php code, and then the cf code:

PHP version

<?php

    //declare our assets

    $name = stripcslashes($_POST['name']);

    $emailAddr = stripcslashes($_POST['email']);

    $comment = stripcslashes($_POST['comment']);

    $subject = stripcslashes($_POST['subject']);   

    $contactMessage = "Message: $comment \r \n From: $name \r \n Reply to: $emailAddr";

    //validate the email address on the server side

    if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailAddr) ) {

        //if successful lets send the message

        mail('/*RECIPIENT EMAIL ADDRESS*/', $subject, $contactMessage);

        echo('success'); //return success callback

    } else {

        echo('An invalid email address was entered'); //email was not valid

    }

?>


This is the cf version I'm working on:

<cfparam name="FORM.name" default="">

<cfparam name="FORM.emailAddr" default="">

<cfparam name="FORM.comment" default="">

<cfmail to="info@astie.com"

        from="#form.emailAddr#"

        subject="Feedback"

        type="html"

        server="mail.asite.com"

        port="25">

<cfmailparam name="X-Priority" value="1"/>

<font face="Verdana, Arial, Helvetica, sans-serif" color="##000000" size="2">

<b>Feedback Form!!</b><br>

  <br>

  <b>Customer Name:</b> #form.name#<br>

  <b>Customer Email:</b>   #form.emailAddr#<br>

  <br />

    <b>Feedback:</b><br>         

  #form.comment#</font><br>

<br>

</cfmail>

Is this possible? I was thinking a cfif statement.. but am a little unclear how to approach it. I can make the jquery available as well if needed, but If I mirror the code in the phpo it should work without having to mess with the java.
Thanks for any help.

This topic has been closed for replies.

1 reply

Inspiring
February 23, 2012

The php app bases it's action on the validity of the email address, not whether or not a message was sent.  You can simplify this immensely by:

on your form page, use the validate attribute of the cfinput tag.

on your action page, use the isValid() function.

All that jquery stuff will then become unnecessary.

Known Participant
February 23, 2012

the form is written in jquery. It's a slide in form, open the web page, there's a tab on the right, click it and the form slides out, I'm trying to make cf mimic the php and slip it into the place of the php emailer.