PDA

View Full Version : [PHP] formattazione testo


tex_willer87
16-07-2010, 14:18
Ciao a tutti!! mi stavo chiedendo se è possibile fare una cosa del genere.
Ho creato il file inviamail.php con all'interno le istruzioni che pescano i dati da un form di inserimento dati, li mettono insieme e invia la mail al mittente. La mail che arriva però non è molto bella da vedere e ciò che vorrei fare è inserire del testo in bold e modificare il font. E' possibile?
Questo è il codice.
Grazie.

<?php
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
$telefono=$_POST['telefono'];
$mail=$_POST['email'];
$messaggio=$_POST['messaggio'];
$to='xxxxx@xxx.xxx';
$subject='Richiesta informazioni da sito cortebolla.it';
$message='<p><b>Richiesta informazioni da sito</b></p> cortebolla.it' ."\n\r" .'Nominativo: ' .$nome .' ' .$cognome."\n\r" .' Telefono: ' .$telefono ."\n\r" .' E-mail: '.$mail ."\n\r" .' Messaggio: '.$messaggio;
$head = "From: ".$mail ."\n\r";
mail($to, $subject, $message, $head);
header("location:http://www.sitoweb.com/contatti.php?messaggio=yes");
?>

wingman87
16-07-2010, 17:59
Se guardi sulla documentazione di mail() c'è un esempio di invio di email formattata con html. In pratica basta impostare alcuni campi nell'header. Ti riporto qui un esempio preso da lì:
<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>