Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,476

    [php] Inviare mail nel formato HTML

    Ciao raga,

    ho questa funzioncina che invia i messaggi di una news letter

    Codice PHP:
    function admin_send_msg() {
     
    // Sends the message to all subscribers on the list.
     
    global $list_name$list_file$owner_email;
      
    set_time_limit(0);
     
    $subject stripslashes($GLOBALS[subject]);
     
    $message stripslashes($GLOBALS[message]);
     
    $subject str_replace("%%""\""$subject);
     
    $message str_replace("%%""\""$message);

     
    $headers "From: \"$list_name\" <$owner_email>\r\nReply-To: $owner_email\r\nX-Sender: $owner_email\r\nX-UnsubscribeURL: [url]http://[/url]$GLOBALS[HTTP_HOST]$GLOBALS[SCRIPT_NAME]\r\nX-Mailer: PHPMailList V$GLOBALS[version] [url]http://php.warpedweb.net/\r\nX-AntiSpam:[/url] PHPMailList did not send you this email, review below for sender info.\r\nX-AntiSpam: Sent by $GLOBALS[REMOTE_ADDR]\r\n";

     if (
    $GLOBALS[SERVER_ADMIN]) $headers .= "X-AntiSpam: Server Administrator $GLOBALS[SERVER_ADMIN]\r\n"

     if (
    $GLOBALS['use_sig'] == "on"$message .= $GLOBALS['sig'];

     
    $sucess_count 0;
     
    $fail_count 0;

     
    $addresses = @file($list_file) or die("<center>[b]The list data file could not be opened.[/b]
    Check the path and permissions.</center>"
    );
     
    $addresses[] = $owner_email;
     
    set_time_limit(0);
     foreach (
    $addresses as $email) {
      
    $email trim($email);
      if (
    mail($email$subject$message$headers)) $sucess_count++;
      else 
    $fail_count++;
     }
     echo 
    "<h3 align=\"center\">Your message was sucessfully sent to $sucess_count addresses.</h3><h4 align=\"center\">There was $fail_count unsucessfully sent.</h4>";

    Volevo chiedere, come si modifica per l'invio di email in formato html?


    grazie a tutti.


    dies

  2. #2

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,476
    ciao ho provato a modificare in questo modo, ho aggiunto le righe in grassetto...

    codice:
    function admin_send_msg() {
     // Sends the message to all subscribers on the list.
     global $list_name, $list_file, $owner_email;
      set_time_limit(0);
     $subject = stripslashes($GLOBALS[subject]);
     $message = stripslashes($GLOBALS[message]);
     $subject = str_replace("%%", "\"", $subject);
    $body_top = "--Message-Boundary\n"; 
    $body_top .= "Content-type: text/html; charset=iso-8859-1\n"; 
    $body_top .= "Content-transfer-encoding: 7BIT\n"; 
    $body_top .= "Content-description: Mail message body\n\n";   $message = $body_top.str_replace("%%", "\"", $message);
    
     $headers = "From: \"$list_name\" <$owner_email>\r\nReply-To: $owner_email\r\nX-Sender: $owner_email\r\nX-UnsubscribeURL: http://$GLOBALS[HTTP_HOST]$GLOBALS[SCRIPT_NAME]\r\nX-Mailer: PHPMailList V$GLOBALS[version] http://php.warpedweb.net/\r\nX-AntiSpam: PHPMailList did not send you this email, review below for sender info.\r\nX-AntiSpam: Sent by $GLOBALS[REMOTE_ADDR]\r\n";
    
     if ($GLOBALS[SERVER_ADMIN]) $headers .= "X-AntiSpam: Server Administrator $GLOBALS[SERVER_ADMIN]\r\n"; 
    
     if ($GLOBALS['use_sig'] == "on") $message .= $GLOBALS['sig'];
    
     $sucess_count = 0;
     $fail_count = 0;
    
     $addresses = @file($list_file) or die("<center>The list data file could not be opened.
    Check the path and permissions.</center>");
     $addresses[] = $owner_email;
     set_time_limit(0);
     foreach ($addresses as $email) {
      $email = trim($email);
      if (mail($email, $subject, $message, $headers)) $sucess_count++;
      else $fail_count++;
     }
     echo "<h3 align=\"center\">Your message was sucessfully sent to $sucess_count addresses.</h3><h4 align=\"center\">There was $fail_count unsucessfully sent.</h4>";
    }

    ma la mail mi arriva sempre in formato testuale..


    Dove sbaglio?


    ciao,


    dies

  4. #4

    Funzione Mail

    <?
    /*

    Funzione per spedire email testuali, in formato HTML o testuali con allegato

    Parametri:
    - "tipo" (testo, html, allegato);
    - "mittente" indirizzo email del mittente;
    - "destinatario" indirizzo email del destinatario;
    - "oggetto" oggetto della mail
    - "body" corpo della mail, in formato testo se scegliamo di spedire la mail in formato testo o con allegato, file HTML se dobbiamo
    spedire una pagina HTML
    - "nome_file" il nome del file, con tanto di percorso, del file che vogliamo allegare alla mail
    - "file_conferma" nome del file che deve visualizzare la funzione dopo aver spedito correttamente la mail

    */
    function sendmail ($tipo, $mittente, $destinatario, $oggetto, $body, $nome_file, $file_conferma) {

    // definizione messaggi di errore
    $errore_formato_indirizzo_mail = "Inserisci un indirizzo E-Mail, del mittente o del destinatario, corretto.";
    $errore_tipo = "Scegli il tipo di mail da inviare (testo / HTML).";
    $errore_oggetto = "Inserisci l'ogetto della mail.";
    $errore_body = "Inserisci il testo della mail.";
    $errore_nome_file = "Inserisci il nome del file da allegare.";
    $errore_conferma = "Indica il file da visualizzare come conferma invio mail.";
    $errore_spedizione = "Inpossibile inviare l'email.";

    // controllo parametri della funzione e restituzione degli errori
    if (!$tipo) { return $errore_tipo; }
    if (!$oggetto) { return $errore_oggetto; }
    if (!$body) { return $errore_body; }
    if ($tipo == "allegato" and !$nome_file) { return $errore_nome_file; }
    if (!$file_conferma) { return $errore_conferma; }

    // controllo caratteri che deve contenere l'indirizzo email del mittente
    $mail_mittente = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $mittente);
    $mail_destinatario = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $destinatario);

    // se l'email è nel giusto formato (xxxx@xxx.xxx) spedisci email
    if ($mail_mittente != false and $mail_destinatario != false) {

    //definizione degli headers
    $uid = strtoupper(md5(uniqid(time())));
    $headers = "From: $mittente\r\n";
    $headers .= "MIME-Version: 1.0\r\n";

    $boundary = uniqid($uid);

    // controllo del tipo di email (testo, HTML) da spedire
    switch ($tipo) {
    case 'testo':
    // definizione email di testo
    $spedizione = mail($destinatario, $oggetto, $body,
    "From: $mittente\nReply-To: $mittente\nX-Mailer: PHP/" . phpversion());
    break;
    case 'html':
    // definizione email HTML
    $headers .= "From: $mittente <$mittente>\n".
    "MIME-Version: 1.0\n".
    "Content-Type: multipart/mixed; boundary=$uid\n\n".
    "--$uid\n".
    "--$uid\n".
    "Content-Type: text/html;\n".
    "Content-Transfer-Encoding: 7bit\n\n";

    $spedizione = mail($destinatario, $oggetto, $body, $headers );
    break;
    case 'allegato':
    // definizione email con allegato
    $mime_boundary = "==Multipart_Boundary_x{$uid}x";

    $headers .= "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";

    $email_message .= "--{$mime_boundary}\n" .
    "Content-Type:text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $email_message .= $body . "\n\n";

    // lettura file da allegare
    $file = fopen($nome_file,'rb');
    $data = fread($file,filesize($nome_file));
    fclose($file);

    // encoding base64
    $data = chunk_split(base64_encode($data));

    $email_message .= "--{$mime_boundary}\n" .
    "Content-Type: application/octet-stream;\n" .
    " name=\"{$nome_file}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" .
    "--{$mime_boundary}--\n";

    $spedizione = mail($destinatario, $oggetto, $email_message, $headers);
    break;
    }

    if($spedizione) {
    // visualizzazione messaggio di conferma spedizione
    require($file_conferma);
    } else {
    // visualizzazione messaggio d'errore spedizione
    return $errore_spedizione;
    }
    } else {
    // altrimenti restituisci il messaggio di errore
    return $errore_formato_indirizzo_mail;
    }

    }
    ?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.