2012-06-21 19 views
16

Sto usando PHPmailer per inviare email.PHPmailer invia HTML CODICE

ho anche usato HTML = contenuto Vero tipo

$mail = new PHPMailer(); 

$mail->IsSMTP();     // send via SMTP 
$mail->Host  = $Host; 
$mail->SMTPAuth = true;    // turn on SMTP authentication 
$mail->Username = $Username; 
$mail->Password = $Password; 

$mail->From  = $From; 
$mail->FromName = $FromName; 

    $mail->AddAddress($To , $ToName); 

$mail->WordWrap = 50;    // set word wrap 
    $mail->Priority = 1; 
$mail->IsHTML(true); 
$mail->Subject = $Subject; 
$mail->Body  = $Body; 

Una volta che il messaggio viene inviato vedo il codice HTML invece del contenuto controlli prego sotto

enter image description here

** Non sicuro qual è il problema **

+0

Puoi mostrare il codice che stai usando per riempire il corpo? –

+0

Stai facendo '$ mail-> Corpo ($ tuo_html_html)'? –

+0

@MarcB si sto usando $ mail-> Corpo = $ Corpo; – user580950

risposta

49

Chiamare il metodo isHTML() dopo l'istanza Body puntello erty (intendo $mail->Body) è stato impostato risolto il problema per me:

$mail->Subject = $Subject; 
$mail->Body = $Body; 
$mail->IsHTML(true);  // <=== call IsHTML() after $mail->Body has been set. 
+0

Questo è corretto ma non si dovrebbe mai chiamare '$ mail-> ClearCustomHeaders();' dopo '$ mail-> IsHTML (true)'. 'ClearCustomHeader' elimina la tua formattazione HTML dell'email e il destinatario riceverà invece il codice sorgente HTML. –

-1

solo il necessario per passare vero come argomento a IsHTML function().

2

o se avete ancora problemi è possibile utilizzare questo

$mail->Body = html_entity_decode($Body); 
4

// scusi metodo

C'è msgHTML() inglese del mio principiante, che, anche, chiamare IsHTML().

Hrm ... IsHTML nome è confusa ...

/** 
* Create a message from an HTML string. 
* Automatically makes modifications for inline images and backgrounds 
* and creates a plain-text version by converting the HTML. 
* Overwrites any existing values in $this->Body and $this->AltBody 
* @access public 
* @param string $message HTML message string 
* @param string $basedir baseline directory for path 
* @param bool $advanced Whether to use the advanced HTML to text converter 
* @return string $message 
*/ 
public function msgHTML($message, $basedir = '', $advanced = false) 
-2

fare così-incollare il codice html all'interno del vostro file HTML separato utilizzando il metodo GET.

$mail->IsHTML(true);         
    $mail->WordWrap = 70;         
    $mail->addAttachment= $_GET['addattachment']; $mail->AltBody 
    =$_GET['AltBody']; $mail->Subject = $_GET['subject']; $mail->Body = $_GET['body']; 
-2

tutto ciò che devi fare è aggiungere $ mail-> IsHTML (true); per il codice funziona benissimo ..

0

Nella versione 5.2.7 Io uso questo per inviare testo semplice: $mail->set('Body', $Body);

-2

Cosa mi ha quasi ucciso, ero ho definito $ mail-> AltBody. Dopo aver rimosso questo, tutto ha funzionato