PDA

View Full Version : email php script check boxes


gore.m
07-13-2010, 03:23 PM
Hello,

I have done my form http://www.svatebni-smutecni-kytice-brno.cz/form.html

Im using this script to send it http://www.dreamweaverclub.com/dreamweaver-php-form.php (http://www.dreamweaverclub.com/forum/../dreamweaver-php-form.php)

I have two problems:

1| Is it possible edit encoding to UTF8.. or other? Im getting strange result to email (I need set up it for Czech language)

2| Form include check boxes. Problem is: Im getting only last users choice from an check box group. Is it possible to tweak script so that I get all user choises from an check box group?


thanks you very much

edbr
07-14-2010, 01:25 AM
not tested but i found this function that you can maybe tweak in the the script

function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
mail (http://www.php.net/mail)($to, '=?UTF-8?B?'.base64_encode (http://www.php.net/base64_encode)($subject).'?=', $message, $header_ . $header);
}


for multiple vales from the check box you will need to use an array [] in your fieldname so php will know it has more values

gore.m
07-14-2010, 09:29 AM
Thanks you very much for your reply.

I have tried that and have used google a lot, but Im new in this and Im confused :mrgreen:

Script:
I have tried to apply code to script, but it doesnt work. Is there an special place where it should be placed? Or should I use only an part of code and replace code in script?

Array:
I have used this combinations:

<label>
<input type="checkbox" name="array[]" value="Design" id="Naprodejn283kv283tinm283vprvniacute345ad283zaujmev ybertepouzedv283mo382nosti:_0" />
Design</label>
<br />
<label>
<input type="checkbox" name="array[]" value="Vůně" id="Naprodejn283kv283tinm283vprvniacute345ad283zaujmev ybertepouzedv283mo382nosti:_1" />
Vůně</label>
</p>
<p>
<label>
<input type="checkbox" name="array[]" value="Květiny" id="Naprodejn283kv283tinm283vprvniacute345ad283zaujmev ybertepouzedv283mo382nosti:_5" />
Květiny
</label>or this

<label>
<input type="checkbox" name="array[zaujme]" value="Design" id="Naprodejn283kv283tinm283vprvniacute345ad283zaujmev ybertepouzedv283mo382nosti:_0" />
Design</label>
<br />
<label>
<input type="checkbox" name="array[zaujme]" value="Vůně" id="Naprodejn283kv283tinm283vprvniacute345ad283zaujmev ybertepouzedv283mo382nosti:_1" />
Vůně</label>
</p>
<p>
<label>
<input type="checkbox" name="array[zaujme]" value="Květiny" id="Naprodejn283kv283tinm283vprvniacute345ad283zaujmev ybertepouzedv283mo382nosti:_5" />
Květiny
</label>
But it doestnt work. Im getting this result to email:
array: A rray

thanks you very much

edbr
07-15-2010, 01:49 AM
ok give me some time and ill try to sort this .

gore.m
07-15-2010, 06:43 AM
Thanks you very much

edbr
07-16-2010, 04:02 AM
ok see how you do with this. this is a simple form with a couple of fields and a checkbox ad edit as you want but notice where i put the [] save as form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>
</head>

<body>
<form action="test.php" method="post">
<input name="email" type="text" />
<input name="name" type="text" />

<p>
<label>
<input type="checkbox" name="Checkbox[]" value="first" />
first</label>
<br />
<label>
<input type="checkbox" name="Checkbox[]" value="second" />
second</label>
<br /><input name="" type="submit" value="Submit" />
</p>
</form>
</body>
</html>

This will send the arrayin an html email, i havent tested the UT8 side of it so let me know. if all is good we should look to add some server side validation but lets try this first. save this as test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test mail</title>
</head>

<body>
<?php
// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
//$emailadd = 'mail@rdsnetworks.net';
$emailadd = 'mail@rdsnetworks.net';
// Where to redirect after form is processed.
$url = 'http://www.rdsnetworks.net/confirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\r\n".'<br>';

foreach($_POST as $key => $value){
if(!(!isset($value))){$set=1;}
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}
$to= $emailadd;


//echo $message ;

function UTF8_mail($to, $subject, $message)
{

$message="=?UTF-8?B?".base64_encode($subject)."?=\n";

$headers .=
"Content-Type: text/html; "
. "charset=UTF-8; format=flowed\n"
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";

return mail($to, $subject, $message, $headers);
}

mail($to, $subject, $message, $headers);

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

</body>
</html>

upload both to your site ,go to form.html fill in and submit

gore.m
07-16-2010, 10:15 AM
THANKS YOU VERY MUCH :-)

Check boxes are working. But problem with "chart set" survived :???: I have tried change UTF8 to ISO-8859, ISO-8859-1, ISO-8859-2 but it doesnt work.

edbr
07-16-2010, 10:22 AM
no prob ill have to look this up myself i have not had to use it but it is documented so im sure there is a solution

edbr
07-16-2010, 10:34 AM
ok i tried a quick revision , give this a try . Im out the door now Friday night beckons

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test mail</title>
</head>

<body>
<?php
// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
//$emailadd = 'mail@rdsnetworks.net';
$emailadd = 'mail@rdsnetworks.net';
// Where to redirect after form is processed.
$url = 'http://www.rdsnetworks.net/confirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\r\n".'<br>';

foreach($_POST as $key => $value){
if(!(!isset($value))){$set=1;}
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}
$to= $emailadd;


//echo $message ;

function UTF8_mail($to, $subject, $message)
{

$message="=?UTF-8?B?".base64_encode($subject)."?=\n";

$headers .=
"Content-Type: text/html"
. "charset=UTF-8\r\n""
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";

return mail($to, $subject, $message, $headers);
}

mail($to, $subject, $message, $headers);

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

</body>
</html>

gore.m
07-16-2010, 11:09 AM
Thankys you very much.
Unfortunately not working. :(

edbr
07-17-2010, 04:05 AM
try again i made an edit to it

gore.m
07-17-2010, 12:14 PM
Thanks you! But, no, it is same. Email is not readable. Is it problem of script or chart set?

edbr
07-19-2010, 01:26 AM
good question, use edit below, this i have commented out the redirect an it will echo the message on the page, let me if it displays correctly it is a mail script problem if not its a charset problem

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test mail</title>
</head>

<body>
<?php
// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
//$emailadd = 'mail@rdsnetworks.net';
$emailadd = 'mail@rdsnetworks.net';
// Where to redirect after form is processed.
$url = 'http://www.rdsnetworks.net/confirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\r\n".'<br>';

foreach($_POST as $key => $value){
if(!(!isset($value))){$set=1;}
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}
$to= $emailadd;


echo $message ;

function UTF8_mail($to, $subject, $message)
{

$message="=?UTF-8?B?".base64_encode($subject)."?=\n";

$headers .=
"Content-Type: text/html"
. "charset=UTF-8\r\n""
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";

return mail($to, $subject, $message, $headers);
}

mail($to, $subject, $message, $headers);

// echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

</body>
</html>

gore.m
07-19-2010, 01:57 PM
Yes, it is ok. I see corect letters :wink:

edbr
07-20-2010, 01:24 AM
ok its the mail script then. ill have another look at it later

gore.m
07-20-2010, 06:10 AM
Thanks you very much

edbr
07-21-2010, 02:49 AM
well i searched around and canyt see why this would not work but there does seem to be a lot of issues reported but try anyway

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test mail</title>
</head>

<body>
<?php
// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
//$emailadd = 'mail@rdsnetworks.net';
$emailadd = 'mail@rdsnetworks.net';
// Where to redirect after form is processed.
$url = 'http://www.rdsnetworks.net/confirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\r\n".'<br>';

foreach($_POST as $key => $value){
if(!(!isset($value))){$set=1;}
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}
$to= $emailadd;

function UTF8_mail($to, $subject, $message)
{


$headers .=
"Content-Type: text/html;"
. "charset=UTF-8\r\n""
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";

return mail($to, $subject, $message, $headers);
}

mail($to, $subject, $message, $headers);

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

</body>
</html>

gore.m
07-21-2010, 12:23 PM
HM. No, not working. There is an goblin inside :-D

edbr
07-22-2010, 02:27 AM
im going to have to pass on this i m afraid at least for now it seemed to me that as far as the message text wuld not need decoding as it is in the body of the html but i cant find a solution for this , possiblly our davidj can help if he pops in to the forum

gore.m
07-22-2010, 06:06 AM
OK, thanks you very much for your time!

santoshkori
07-22-2010, 08:25 AM
can we add more recipients?? Like CC and BCC in mailer.php iknow it know its possible can but dont how to do that, So can anyone give me code for it. i am new to php.

Thanks in Advance.
:)

edbr
07-22-2010, 08:49 AM
hm try this i just added on the hoof so not tested

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test mail</title>
</head>

<body>
<?php
// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.

$emailadd = 't';

// edit if cc wanted
$mailcc ='';

// edit if bcc wanted
$mailbcc ='';

// Where to redirect after form is processed.
$url = 'http://www.your domain.com';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\r\n".'<br>';

foreach($_POST as $key => $value){
if(!(!isset($value))){$set=1;}
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}
$to= $emailadd;

function UTF8_mail($to, $subject, $message)
{


$headers .=
"Content-Type: text/html;"
. "charset=UTF-8\r\n""
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";
if (!empty($mailcc)) {
$headers.= "Cc: " . $mailcc ."\n";
}

if (!empty($mailbcc)) {
$headers.= "Bcc: " . $mailbcc ."\n";
}
return mail($to, $subject, $message, $headers);
}

mail($to, $subject, $message, $headers);

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

</body>
</html>

santoshkori
07-22-2010, 09:56 AM
Thanks edbr (http://www.dreamweaverclub.com/forum/member.php?u=22485) it working g8...
but in both email account it showing [SPAM-LOW] in Subject is there any parameters code to prevent that..
please guide me in that.

Again Thanks