2016-07-13 5 views
0

Je suis nouveau Swiftmailer et je pourrais envoyer avec succès e-mail à l'utiliser. Je dois ajouter un modèle html au corps de l'email. Je ne suis pas sûr de savoir comment faire ça? Ce est le code que je l'habitude demodèle html au corps e-mail rapide

function sendMail($destinationEmail){ 

    // Create the mail transport configuration 
$transport = Swift_MailTransport::newInstance(); 

$html = "<html> 
<head> 
<title>Alerting System</title> 
<style type=\"text/css\"> 
<!-- 
table { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
border: thin solid; 
} 
th { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
color: #f0f0f0; 
background-color: #ff0000; 
font-size: 12px; 
} 
td { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
color: #000000; 
font-size: 10px; 
border: thin solid; 
} 
body { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
font-size: 10px; 
} 
--> 
</style> 
<head> 
<body> 
<CENTER> 
<TABLE width=\"50%\"> 
<TBODY> 
<tr> 
<th >test</th> 
</tr> 
</TBODY> 
</TABLE> 
<br> 
Alerting and Reporting System 
</CENTER></BODY></HTML> 
"; 


// Create the message 
$message = Swift_Message::newInstance(); 
$message->setTo(array(
    $destinationEmail => "test", 
    $destinationEmail => "test mail" 
)); 
$message->setSubject("This email is sent using Swift Mailer"); 
$message->setBody("You're our best client ever."); 
$message->setFrom("[email protected]", "Alerts"); 

$message->attach($html, "text/html"); 


// Send the email 
$mailer = Swift_Mailer::newInstance($transport); 
$mailer->send($message); 
} 

Comment puis-je ajouter cette variable $ html un modèle e-mail? Toute suggestion serait appréciée.

Répondre

0

Utilisez cette

$html = "<html> 
<head> 
<title>Alerting System</title> 
<style type=\"text/css\"> 
<!-- 
table { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
border: thin solid; 
} 
th { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
color: #f0f0f0; 
background-color: #ff0000; 
font-size: 12px; 
} 
td { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
color: #000000; 
font-size: 10px; 
border: thin solid; 
} 
body { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
font-size: 10px; 
} 
--> 
</style> 
<head> 
<body> 
<CENTER> 
<TABLE width=\"50%\"> 
<TBODY> 
<tr> 
<th >test</th> 
</tr> 
</TBODY> 
</TABLE> 
<br> 
Alerting and Reporting System 
</CENTER></BODY></HTML> 
"; 


    $message->setBody($html,'text/html' // Mark the content-type as HTML); 
+0

J'ai essayé, mais de ne pas ajouter le type de contenu. Merci de votre aide –