Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
JF213 #1
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
-
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... -
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... -
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: ... -
coldfusion cms
Hi: If i want to use a coldfusion based cms (content management system) which one is the best choice? Thanks Benign -
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... -
gumshoe #2
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
-
Der Nickname #3
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



Reply With Quote

