Jump to content

[SOLVED] PHP FORM VALIDATION WITH XML AND FLASH


apolopes

Recommended Posts

Hello all,

 

can any1 help me with this code:

 

<?

foreach ($_POST as $key => $value){

 

if ($key != 'emailTo' && $key != 'smtp_server' && $key != 'smtp_port' && $key != 'email_from' && $key != 'email_subject' && $key != 'plain_text'){

 

$mail_body .= '<b>'.str_replace('_',' ',$key).'</b>:<br/>';

 

$mail_body .= ''.stripslashes($value).'<br/>';

}

}

//-----------------------------------------------------------------

 

 

 

$message = '<html><body>'.$mail_body.'</body></html>'; //  mail body

 

if ($_POST['plain_text']=='true') {

 

$message = str_replace('<br/>',"\r\n", $message);

 

$message = strip_tags($message);

 

} else {

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

 

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

}

 

 

$to = $_POST['emailTo'];

 

$from = $_POST['email_from'];

 

$subject = $_POST['email_subject'];

 

$smtp_server = $_POST['smtp_server'];

 

$smtp_port = $_POST['smtp_port'];

 

 

 

$headers .= 'To: '.$to. "\r\n";

 

$headers .= 'From: Site visitor ' .$from. "\r\n";

 

 

 

if (mail($to, $subject, $message, $headers)){ // sending mail

 

print('&mail=1');  //succes

 

} else {

 

print('&mail=0');//failure

 

}

 

?>

 

it is supposed to send the contents of a form in a flash website, I do get the "sent" output but the email never reaches the mailbox so I believe there is something wrong with it...

Just in case here is the code on the xml configuration file of the form (yes flash is calling it).

 

<?

foreach ($_POST as $key => $value){

 

if ($key != 'emailTo' && $key != 'smtp_server' && $key != 'smtp_port' && $key != 'email_from' && $key != 'email_subject' && $key != 'plain_text'){

 

$mail_body .= '<b>'.str_replace('_',' ',$key).'</b>:<br/>';

 

$mail_body .= ''.stripslashes($value).'<br/>';

}

}

//-----------------------------------------------------------------

 

 

 

$message = '<html><body>'.$mail_body.'</body></html>'; //  mail body

 

if ($_POST['plain_text']=='true') {

 

$message = str_replace('<br/>',"\r\n", $message);

 

$message = strip_tags($message);

 

} else {

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

 

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

}

 

 

$to = $_POST['emailTo'];

 

$from = $_POST['email_from'];

 

$subject = $_POST['email_subject'];

 

$smtp_server = $_POST['smtp_server'];

 

$smtp_port = $_POST['smtp_port'];

 

 

 

$headers .= 'To: '.$to. "\r\n";

 

$headers .= 'From: Site visitor ' .$from. "\r\n";

 

 

 

if (mail($to, $subject, $message, $headers)){ // sending mail

 

print('&mail=1');  //succes

 

} else {

 

print('&mail=0');//failure

 

}

 

?>

 

and the structure code in xml:

 

<?xml version="1.0" encoding="utf-8"?>

<contactFormStructure>

 

<formItems>

 

<item id="1" label="Name" required="true">

 

</item>

 

<item id="2" label="Phone">

 

                        <restrict>+-.0-9</restrict>

</item>

 

<item id="3" label="Fax">

 

        <restrict>+-.0-9</restrict>

                </item>

 

<item id="4" label="E-mail" required="true">

 

<validator>EmailValidator</validator>

</item>

 

<item id="5" label="Message" required="true">

 

</item>

 

</formItems>

 

</contactFormStructure>

 

 

Any help would be appreciated, I just cant figure it out on my own...

1: Please use the code tags when posting code on the forums. It really does help!

2: Have you tried debugging your script by outputting to the screen if a IF statement is proved correct etc? Is it telling you that the mail was sent?

3: Please tell me you've checked your junk mail :P

1: Please use the code tags when posting code on the forums. It really does help!

2: Have you tried debugging your script by outputting to the screen if a IF statement is proved correct etc? Is it telling you that the mail was sent?

3: Please tell me you've checked your junk mail :P

 

1: sorry about that  ;)

2: yes it says the mail was sent by that eventhough I havent debugged it I suppose all is good...

3: yup, wished for the first time I had received some junk... but I did not :S

 

I have come up with a simpler one after doing the flash form from scratch but again, cant figured out what is wrong... This time I am getting an error message... I tried cursing the dude that put that error message but hey, it was me :S

 

<?
if(!empty($HTTP_POST_VARS['form_mail']) || !empty($HTTP_POST_VARS['form_message']) || !empty($HTTP_POST_VARS['form_subject']) || !empty($HTTP_POST_VARS['form_name']))
{
$to = "[email protected]";
$subject = stripslashes($HTTP_POST_VARS['form_subject']);
$body = stripslashes($HTTP_POST_VARS['form_message']);
$body .= "\n\n---------------------------\n";
$body .= "Mail sent by: " . $HTTP_POST_VARS['form_name'] . " <" . $HTTP_POST_VARS['form_mail']  . ">\n";
$header = "From: " . $HTTP_POST_VARS['form_name'] . " <" . $HTTP_POST_VARS['form_mail'] . ">\n";
$header .= "Reply-To: " . $HTTP_POST_VARS['form_name'] . " <" . $HTTP_POST_VARS['form_mail'] . ">\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";
if(@mail($to, $subject, $body, $header))
{
	echo "output=Sent";
} else {
	echo "output=Error";
}
} else {
echo "output=Error";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.