Hi,
I'm having a similar problem with another script. It's a form to which should allow to send an attachment. The file is being uploaded but the mail is not sent. I implemented your correction in this script but I'm missing something.
Anyone has any suggestions?
thanks
Regards
RF
<?php
function mail_attach($para, $de, $assunto, $mensagem, $ficheiro) {
$mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1));
$data = chunk_split(base64_encode(implode("", file($ficheiro))));
$header = "From: ".$de."\r\n";
$header.= "To: ".$para."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: multipart/mixed;\r\n";
$header.= " boundary=\"".$mime_boundary."\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= $mensagem."\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: Application/Octet-Stream; name=\"".$ficheiro."\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--" . $mime_boundary . "\r\n";
if(mail($para, $de, $assunto, $content, $header)) {
return TRUE;
}
return FALSE;
}
if($_FILES['userfile'] != "") {
//Se houver anexo
$data = $_FILES['userfile']['name'];
$data2 = $_FILES['userfile']['tmp_name'];
copy($data2, $data)
or die ("Houve um erro na cópia do ficheiro, o envio da mensagem será abortado.");
//mail_attach ("destinatário", nome e e-mail do utilizador, "assunto", texto da mensagem, ficheiro anexo);
$name_field = $_POST['nome'];
$email_field = $_POST['email'];
$mensagem = $_POST['nifrec'];
$body = "DADOS DO PARTICIPANTE\r\n";
$body .= "\r\n nome: " . $_POST['nome'];
$body .= "\r\n afiliação: " . $_POST['afilicao'];
$body .= "\r\n departamento: " . $_POST['departamento'];
$body .= "\r\n morada: " . $_POST['morada'];
$body .= "\r\n código postal: " . $_POST['codpost1'] . " - " . $_POST['codpost2'] . " " . $_POST['localidade'] ;
$body .= "\r\n telefone: " . $_POST['telefone'] . " - " . "fax: " . $_POST['fax'] ;
$body .= "\r\n e-mail: " . $_POST['email'];
$body .= "\r\n\r\n dias seleccionados: " . $_POST['allitems'];
$body .= "\r\n valor total: " . $_POST['answer'] . " Euros";
$body .= "\r\n \r\n \r\n DADOS PARA EMISSÃO DE RECIBO \r\n ";
$body .= "\r\n nome/ entidade: " . $_POST['nomerec'];
$body .= "\r\n morada: " . $_POST['moradarec'];
$body .= "\r\n código postal: " . $_POST['codpost1rec'] . " - " . $_POST['codpost2rec'] . " " . $_POST['localidaderec'] ;
$body .= "\r\n NIF: " . $_POST['nifrec'];
mail_attach("ricardo.ferreira@pointoview.net" . "," . $email_field, $name_field . "<" . $email_field . ">", $assunto . " (via attach script)", $body, $data)
or die ("O envio dos seus dados falhou! (via attach script)");
header("location: obrigado.html");
unlink ($data);
} else {
//Se não houver anexo
//mail ("destinatário", "assunto", texto da mensagem, nome e e-mail do utilizador);
$name_field = $_POST['nome'];
$email_field = $_POST['email'];
$assunto = "Inscrição de: " . $_POST['nome'];
$body = "DADOS DO PARTICIPANTE\r\n";
$body .= "\r\n nome: " . $_POST['nome'];
$body .= "\r\n afiliação: " . $_POST['afilicao'];
$body .= "\r\n departamento: " . $_POST['departamento'];
$body .= "\r\n morada: " . $_POST['morada'];
$body .= "\r\n código postal: " . $_POST['codpost1'] . " - " . $_POST['codpost2'] . " " . $_POST['localidade'] ;
$body .= "\r\n telefone: " . $_POST['telefone'] . " - " . "fax: " . $_POST['fax'] ;
$body .= "\r\n e-mail: " . $_POST['email'];
$body .= "\r\n\r\n dias seleccionados: " . $_POST['allitems'];
$body .= "\r\n valor total: " . $_POST['answer'] . " Euros";
$body .= "\r\n \r\n \r\n DADOS PARA EMISSÃO DE RECIBO \r\n ";
$body .= "\r\n nome/ entidade: " . $_POST['nomerec'];
$body .= "\r\n morada: " . $_POST['moradarec'];
$body .= "\r\n código postal: " . $_POST['codpost1rec'] . " - " . $_POST['codpost2rec'] . " " . $_POST['localidaderec'] ;
$body .= "\r\n NIF: " . $_POST['nifrec'];
mail("ricardo.ferreira@pointoview.net" . "," . $_POST['email'], $assunto . " (via no attach script)", $body, "From:\"" . $name_field ."\"<" . $email_field . ">\n") or
die ("O envio dos seus dados falhou! (via no attach script)");
header("location: obrigado.html");
}
?>