Ok ragazzi, questo è il mio primo thread e ho cercato online ma senza fortuna. Sto facendo uno stage e sto lavorando a un progetto che richiede la creazione di una pagina Web che genera un file PDF quando un utente invia le sue informazioni. Non appena un cliente fa clic sul pulsante di invio, 3 cose devono accadere:Invio di un messaggio di posta elettronica con un allegato di file PDF tramite PHP
- di memorizzare le informazioni nel database (fatto),
- Invia il personale una e-mail con le nuove informazioni del cliente (fatto), e
- Inviare al cliente un'e-mail di "messaggio di ringraziamento" con un allegato di file pdf (non funzionante).
Voglio dire, il cliente non riceverà un'e-mail, ma quando lui/lei apre il file pdf, ottengo il seguente messaggio di errore:
"Acrobat potrebbe non OEN 'nome_file' perché è o non è un tipo di file supportato o perché il file è stato danneggiato (ad esempio, è stato inviato come allegato e non è stato decodificato correttamente) ... "
Si prega di tenere presente che questa è la mia prima volta fare un progetto sulla creazione di un allegato di file pdf. Se qualcuno potesse aiutarmi a risolvere questo problema, sarebbe fantastico. Grazie!
Ecco il mio codice:
<?php
// once there are no errors, as soon as the customer hits the submit button, it needs to send an email to the staff with the customer information
$msg = "Name: " .$_POST['name'] . "\n"
."Email: " .$_POST['email'] . "\n"
."Phone: " .$_POST['telephone'] . "\n"
."Number Of Guests: " .$_POST['numberOfGuests'] . "\n"
."Date Of Reunion: " .$_POST['date'];
$staffEmail = "staffinfo";
mail($staffEmail, "You have a new customer", $msg); // using the mail php function to send the email. mail(to, subject line, message)
//once the customer submits his/her information, he/she will receive a thank you message attach with a pdf file.
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial", "B", 16);
$pdf->Cell(40, 10, "Hello World!");
// email information
$to = $_POST['email'];
$from = $staffEmail;
$subject = "Thank you for your business";
$message = "Thank you for submitting your information!";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "yourinformation.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// encode data (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Enconding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charsrt=\"iso-8859-1\"".$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
//$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Type: application/zip; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
mail($to, $subject, $message, $headers);
}
}
?>
ho notato che hai application/zip. Prova invece l'applicazione/pdf. – Raisen
L'ho fatto anch'io, ma non funzionerà. –
Non ho ancora pensato correttamente, ma IIRC l'eol per le intestazioni MIME è sempre "\ r \ n" il valore effettivo in 'PHP_EOL' varia a seconda del sistema operativo; che potrebbe mettere una chiave in lavorazione nella tua var $ headers; anche se secondo le specifiche dovrebbe essere tollerante: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html (19.3) – CD001