Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    27

    Inviare email con php dal sito in formato html

    CIAO A TUTTI, SUL MIO SITO HO UN PICCOLO FORM PER ISCRIVERE GLI UTENTI. A COMPLETAMENTO INVIA UNA MAIL CON I DATI DEL REGISTRANTE.

    ECCO IL CODICE
    $destinatario ='XXXX@XXX.it';
    $oggetto = 'ISCRIZIONE';
    $info = '<br>Nome: <b>' . $nome . '</b><br>';



    $mail_in_html = "MIME-Version: 1.0\r\n";
    $mail_in_html .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $mail_in_html .= "From: <$mail_from>";


    mail($destinatario,$oggetto,$info,$mail_in_html);

    PURTROPPO NON MI INTERPRETA I TAG HTML, DOVE HO SBAGLIATO?

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2005
    residenza
    http://www.okkioalprezzo.com/it/
    Messaggi
    206

    Prova questa

    Prova questa classe scaricata da github:


    Demo invio:
    Codice PHP:
    <?php
    require_once 'mailer.class.php';
    $mail = new Mailer();
    $mail->addHeader('X-Priority: High');
    $mail->setSubject('Subject');
    /* usi questo metodo se devi allegare un file, altrimenti cancelli questa riga*/
    $mail->addAttachment('READMY''...''text/plain'); 

    $mail->html('test@gmail.com''<h1>Тест</h1>')

    ?>


    Codice PHP:
    <?php
    class Mailer {
        protected 
    $charset 'UTF-8',
                  
    $to,
                  
    $from,
                  
    $subject '',
                  
    $headers = array(),
                  
    $attachments = array();

        public function 
    setCharset($value) {
            
    $this->charset $value;
        }

        public function 
    encode($value) {
            return 
    '=?' $this->charset '?B?' base64_encode($value) . '?=';
        }

        public function 
    setFrom($email$name null) {
            
    $this->from $name $this->encode($name) . " <$email>" $email;
        }

        public function 
    setSubject($value) {
            
    $this->subject $this->encode($value);
        }

        public function 
    addHeader($header) {
            
    $this->headers[] = $header;
        }

        public function 
    addAttachment($name$data$type =
                
    'application/octet-stream') {
            
    $name $this->encode($name);
            
    $data chunk_split(base64_encode($data));
            
    $this->attachments[] = compact('name''data''type');
        }

        public function 
    send($to$body$is_html 0) {
            if (
    $this->from) {
                
    $this->headers[] = 'From: ' $this->from;
            }
            
    $content_type 'Content-Type: text/' . ($is_html 'html' 'plain') .
                    
    '; charset=' $this->charset;
            
    $content_transfer_encoding 'Content-Transfer-Encoding: 8 bit';
            if (
    $count count($this->attachments)) {
                
    $boundary uniqid();
                
    $this->headers[] = 'Content-Type: multipart/mixed; boundary="' .
                        
    $boundary '"';
                
    $body  = array("--$boundary"$content_type,
                    
    "$content_transfer_encoding\r\n"$body);
                for (
    $i 0$i $count; ++$i) {
                    
    $body[] = "--$boundary";
                    
    $body[] = "Content-Type: " $this->attachments[$i]['type'] .
                            
    "; name=\"" $this->attachments[$i]['name'] . "\"";
                    
    $body[] = 'Content-Disposition: attachment';
                    
    $body[] = "Content-Transfer-Encoding: base64\r\n";
                    
    $body[] =  $this->attachments[$i]['data'];
                }
                
    $body implode("\r\n"$body) . "--$boundary--";
            }
            else {
                
    $this->headers[] = $content_type;
                
    $this->headers[] = $content_transfer_encoding;
            }
            return @
    mail($to$this->subject$bodyimplode("\r\n",
                    
    $this->headers));
        }

        public function 
    html($to$body) {
            return 
    $this->send($to$body1);
        }
    }
     
    ?>

    Se vuoi una soluzione valida prova PHP Mailer questo è il link: http://phpmailer.worxware.com/
    Ultima modifica di felixaf21; 07-04-2014 a 08:14

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    27
    dimmi se ho capito bene:
    la seconda parte la salvo in un file esterno e lo chiamo mailer.class.php

    invece di
    test@gmail.com ci metto il mio indirizzo email
    invece di
    <h1>Тест</h1> ci metto il mio testo?

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2005
    residenza
    http://www.okkioalprezzo.com/it/
    Messaggi
    206
    Essatto, la seconda parte la salvi in un file esterno se hai intenzione di usarla su più "pagine". Altrimenti puoi inserirla all'interno dello stesso file.
    poi scrivi questo:
    <?php
    /*la riga successiva la usi se la classe (seconda parte del codice ) lo salvi su un file esterno. Altrimenti cancelli*/
    require_once 'mailer.class.php';
    $mail = new Mailer();
    $mail->addHeader('X-Priority: High');
    $mail->setSubject('Titolo del messaggio');
    $mail->setFrom("mittente@email.com", "mittente@email.com");
    $mail->html('destinatario@gmail.com', 'corpo del messaggio in formato html')


    ?>

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    27
    ho provato, la classe la richiamo da un file esterno, ma purtroppo la mail mi ritorna con il codice non interpretato
    Immagini allegate Immagini allegate

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.