In my previous post i strugled with a Mail form, which eventualy got solved with your help.
Now i want to insert some check-boxes in this Mail form.
I've already created the HTML form and the PHP, but something is not working. I can't send the values in the check-boxes to the mail.
This is what i have now:
PHP:
<?php
function is_email($email) {
eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
list($email_comp ,$login, $domain, $sufixies) = $match;
if ($email_comp == $email) {
return true;
} else {
return false;
}
}
// Prepare email to send
if ($_POST['submitted'])
{
$para = "nuno.baixinho@epochmultimedia.com"; //info@aroundfield.pt
$assunto = "contacto via website\r\n";
$conteudo = $_POST['conteudo']."\r\n";
$conteudo .= $_POST['nome']."\r\n";
$conteudo .= $_POST['email']."\r\n";
$conteudo .= $_SESSION['check_msg']."\r\n";
$header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";
$_SESSION['nome'] = "";
$_SESSION['email'] = "";
$_SESSION['conteudo'] = "";
$_SESSION['nome'] = $_POST['nome'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['conteudo'] = $_POST['conteudo'];
// Validate email and required fields
if(!is_email($_POST['email']) || $_POST['email'] == "") {
$erro2 = 1;
$_SESSION['email'] = "";
$sucesso = "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
}
if ($erro1 != 1 && $erro2 != 1) {
if (mail($para, $assunto, $conteudo, $header)) {
$sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
$_SESSION['nome'] = "";
$_SESSION['email'] = "";
$_SESSION['conteudo'] = "";
foreach($_POST['tipo'] as $value) {
$_SESSION['check_msg'] .= "Checked: $value\n";
}
echo $_SESSION['check_msg'];
/*header ("Refresh: 2; url=http://www.epochmultimedia.com/clientes/aroundfield/website/index2.php");*/
} else {
$sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
}
}
}
?>
HTML FORM:
<form action="" method="post">
<p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
<p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
<p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
<p style="color:#FF0000; font-size:12px"><input type="checkbox" name="tipo[]" value="1" /> 1 </p>
<p style="color:#FF0000; font-size:12px"><input type="checkbox" name="tipo[]" value="2" /> 2 </p>
<p style="color:#FF0000; font-size:12px"><input type="checkbox" name="tipo[]" value="3" /> 3 </p>
<p><input type="submit" name="enviar" value="enviar »" /></p>
<input type='hidden' value='1' name='submitted' />
</form>
I have all the values in one variable($conteudo) and i tried to put all the values in the check-boxes in another Session variable($_SESSION) which will be put
inside variable($conteudo). The values in $conteudo(mail,conteudo,nome) are sent to the mail and its all working.Also i can echo the $_SESSION variable and read all the values in the check-boxes.
But i can't send to the mail this values together with the others contained in $conteudo.
What's wrong with this picture?
Thanks in advance!