Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default php to coldfusion

    Hi I am new to coldfusion. I just switched my server from a linux box to
    windows, so a php script that I had no longer works. I want to convert it to
    coldfusion. The script is a form script which check and verifies the fields
    and the email address. Is there a tutorial some where or some place that I can
    convert my php script.

    oh yeah the php was communicating with a FLASH MX form.

    thanks

    <?php
    $name='NAME HERE';
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];
    $name=trim($name);
    $email=trim($email);
    $subject=StripSlashes($subject);
    $message=StripSlashes($message);
    //modify the next line with your own email address
    $toaddress='aaa@aaa.com';


    function validate_email($email) {

    // Function to validate an e-mail address by both checking the
    // format of the address, and then testing it by holding an
    // authorisation conversation with the addresses SMTP server
    //
    // inputs - $email = the email address itself
    //
    // returns - function has a return value of
    // 0 = success
    // 1 = failed, invalid address
    // 2 = system failure


    global $HTTP_HOST;

    // Check for a malformed address (roughly)
    if
    (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
    $email)) {
    // it failed the simple format test, so return with an invalid address
    error
    return 1;
    }
    // otherwise it passes the test so we can go off and do the 'real' validation
    //
    // first split #email up into parts
    list ( $Username, $Domain ) = split ("@",$email);

    // look for an MX record and get the mail host name
    if (checkdnsrr ( $Domain, "MX" )) {
    if (getmxrr ($Domain, $MXrec)) {
    // save the MX hostname ready for Phase 3 testing
    $Mailserver = $MXrec[0];
    } else {
    // there is an MX record, but we failed to retrieve it
    return 2; // return system error NOT invalid address
    }
    } else {
    // in this case there isn't an MX record so assume that the domain
    // portion is also the name of the mail server itself (it can happen)
    // save it as the mailserver address ready for Phase 3 testing
    $Mailserver = $Domain;
    }

    // open a socket connection to the Mailserver
    if ($Connection = fsockopen($Mailserver, 25)) {

    // start the SMTP validation

    if (ereg("^220", $Rubbish = fgets($Connection, 1024))) {
    // it is an SMTP server so you can start talking to it

    // Tell it who you are and get the response (not needed later).
    fputs ( $Connection, "HELO $HTTP_HOST\r\n" );
    $Rubbish = fgets ( $Connection, 1024 );

    // Ask it to accept mail from your $email user - store the response
    (needed later)
    fputs ( $Connection, "MAIL FROM: <{$email}>\r\n" );
    $Fromstring = fgets ( $Connection, 1024 );

    // Ask it to accept mail for your $email user - store the response
    (needed later)
    fputs ( $Connection, "RCPT TO: <{$email}>\r\n" );
    $Tostring = fgets ( $Connection, 1024 );

    // Now tell it you're done with chatting
    fputs ( $Connection, "QUIT\r\n");
    // and close the connection
    fclose($Connection);

    // finally test the resonses did we get OK (type 250) messages?
    if (ereg("^250", $Fromstring) && ereg("^250", $Tostring)) {
    // YAHOOO .. we got a good one
    return 0; // return successful validation
    } else {
    // the server refused the user
    return 1; // return invalid address
    }
    } else {
    // connected, to something but it failed to identfy itself as an SMTP
    server
    // so assume its a bogus address
    return 1; // return invalid address error
    }
    } else {
    // it failed to connect
    return 1; // return invalid address or system error - its your call
    }
    }

    $valid = validate_email($email);

    switch ($valid) {

    case 0:
    mail($toaddress,$subject,$message,"From: $name <$email>");
    //clear the variables
    $name='';
    $email='';
    $subject='';
    $message='';
    echo 'response=passed';
    break;
    case 1:
    echo 'response=invalid';
    break;
    case 2:
    echo 'response=error';
    break;

    }//end switch

    ?>

    JF213 Guest

  2. Similar Questions and Discussions

    1. coldfusion-out.log
      Hi everyone, I checked tones of topics about the increase of the size of coldfusion-out.log. And I get no answer. Aparrently there is no...
    2. Running ColdFusion 5.0 and ColdFusion 6.1 concurrently
      Hi, this is my first post on this forum, I have tried looking but could not find a post that discussed my problem. I am wondering if it is possible...
    3. How to call a coldfusion function defined in other coldfusion file??
      inside a.cfm, it has code fragment: <cfloop> <cfinclude template="b.cfm"> </cfloop> inside b.cfm, it has code fragment: ...
    4. coldfusion cms
      Hi: If i want to use a coldfusion based cms (content management system) which one is the best choice? Thanks Benign
    5. Com+ and Coldfusion 7.1
      I have some DLL's (they sit server side) that were developed in VB 6 and are registered as Com objects with windows XP. How can i access those and...
  3. #2

    Default Re: php to coldfusion

    >> Is there a tutorial some where or some place that I can
    convert my php script.


    Which basically means, "how do I do this in coldfusion?" - you can't really
    'convert' it as such. Is there a tutorial - not sure of any particular one
    to reccomend, but I can reccomend a good website called Google you can use
    to find a few.

    I just switched my server from a linux box to
    > windows, so a php script that I had no longer works

    put php on your windows box?? (if you have control of server??)


    Maybe some other posters will know of a decent tutorial you cam look at.

    "JF213" <webforumsuser@macromedia.com> wrote in message
    news:d0koip$sdk$1@forums.macromedia.com...
    > Hi I am new to coldfusion. I just switched my server from a linux box to
    > windows, so a php script that I had no longer works. I want to convert it
    > to
    > coldfusion. The script is a form script which check and verifies the
    > fields
    > and the email address. Is there a tutorial some where or some place that
    > I can
    > convert my php script.
    >
    > oh yeah the php was communicating with a FLASH MX form.
    >
    > thanks
    >
    > <?php
    > $name='NAME HERE';
    > $email=$_POST['email'];
    > $subject=$_POST['subject'];
    > $message=$_POST['message'];
    > $name=trim($name);
    > $email=trim($email);
    > $subject=StripSlashes($subject);
    > $message=StripSlashes($message);
    > //modify the next line with your own email address
    > $toaddress='aaa@aaa.com';
    >
    >
    > function validate_email($email) {
    >
    > // Function to validate an e-mail address by both checking the
    > // format of the address, and then testing it by holding an
    > // authorisation conversation with the addresses SMTP server
    > //
    > // inputs - $email = the email address itself
    > //
    > // returns - function has a return value of
    > // 0 = success
    > // 1 = failed, invalid address
    > // 2 = system failure
    >
    >
    > global $HTTP_HOST;
    >
    > // Check for a malformed address (roughly)
    > if
    > (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
    > $email)) {
    > // it failed the simple format test, so return with an invalid address
    > error
    > return 1;
    > }
    > // otherwise it passes the test so we can go off and do the 'real'
    > validation
    > //
    > // first split #email up into parts
    > list ( $Username, $Domain ) = split ("@",$email);
    >
    > // look for an MX record and get the mail host name
    > if (checkdnsrr ( $Domain, "MX" )) {
    > if (getmxrr ($Domain, $MXrec)) {
    > // save the MX hostname ready for Phase 3 testing
    > $Mailserver = $MXrec[0];
    > } else {
    > // there is an MX record, but we failed to retrieve it
    > return 2; // return system error NOT invalid address
    > }
    > } else {
    > // in this case there isn't an MX record so assume that the domain
    > // portion is also the name of the mail server itself (it can happen)
    > // save it as the mailserver address ready for Phase 3 testing
    > $Mailserver = $Domain;
    > }
    >
    > // open a socket connection to the Mailserver
    > if ($Connection = fsockopen($Mailserver, 25)) {
    >
    > // start the SMTP validation
    >
    > if (ereg("^220", $Rubbish = fgets($Connection, 1024))) {
    > // it is an SMTP server so you can start talking to it
    >
    > // Tell it who you are and get the response (not needed later).
    > fputs ( $Connection, "HELO $HTTP_HOST\r\n" );
    > $Rubbish = fgets ( $Connection, 1024 );
    >
    > // Ask it to accept mail from your $email user - store the response
    > (needed later)
    > fputs ( $Connection, "MAIL FROM: <{$email}>\r\n" );
    > $Fromstring = fgets ( $Connection, 1024 );
    >
    > // Ask it to accept mail for your $email user - store the response
    > (needed later)
    > fputs ( $Connection, "RCPT TO: <{$email}>\r\n" );
    > $Tostring = fgets ( $Connection, 1024 );
    >
    > // Now tell it you're done with chatting
    > fputs ( $Connection, "QUIT\r\n");
    > // and close the connection
    > fclose($Connection);
    >
    > // finally test the resonses did we get OK (type 250) messages?
    > if (ereg("^250", $Fromstring) && ereg("^250", $Tostring)) {
    > // YAHOOO .. we got a good one
    > return 0; // return successful validation
    > } else {
    > // the server refused the user
    > return 1; // return invalid address
    > }
    > } else {
    > // connected, to something but it failed to identfy itself as an
    > SMTP
    > server
    > // so assume its a bogus address
    > return 1; // return invalid address error
    > }
    > } else {
    > // it failed to connect
    > return 1; // return invalid address or system error - its your call
    > }
    > }
    >
    > $valid = validate_email($email);
    >
    > switch ($valid) {
    >
    > case 0:
    > mail($toaddress,$subject,$message,"From: $name <$email>");
    > //clear the variables
    > $name='';
    > $email='';
    > $subject='';
    > $message='';
    > echo 'response=passed';
    > break;
    > case 1:
    > echo 'response=invalid';
    > break;
    > case 2:
    > echo 'response=error';
    > break;
    >
    > }//end switch
    >
    > ?>
    >

    gumshoe Guest

  4. #3

    Default Re: php to coldfusion

    Hmm, I carry this at home and try to translate, long time ago since my last php. But thanks for your indented code, it is the first I saw in this forum :)
    Der Nickname Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139