2017-04-14 74 views
0

我使用phpmailer發送正常的預定義郵件,它工作正常。 現在我想要做的是,連接我的texteditor與該PHP腳本,所以我可以發送非常好的HTML郵件。 Texteditor是CKEditor的模板。我在寫textedtior enter image description here使用php和html發送郵件

一切都與HTML標籤這樣寫的 enter image description here

然後我有我的PHP腳本從PHPMailer的發送郵件。我一直在考慮發佈所有html標籤作爲post方法,並讓他們進入我的php腳本。也許這不是最好的主意,即使是我不知道如何從輸入標籤中發佈東西。

任何幫助將不勝感激。

ps。 這是我的PHP代碼

date_default_timezone_set('Etc/UTC'); 
require '../PHPMailerAutoload.php'; 
$mail = new PHPMailer; 
$mail->isSMTP(); 
$mail->SMTPDebug = 2; 
$mail->Debugoutput = 'html'; 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 587; 
$mail->SMTPSecure = 'tls'; 
$mail->SMTPAuth = true; 
$mail->Username = "[email protected]"; 
$mail->Password = "?????"; 
$mail->setFrom('[email protected]', 'First Last'); 
$mail->addReplyTo('[email protected]', 'First Last'); 
$mail->addAddress('[email protected]', 'John Doe'); 
$mail->Subject = 'PHPMailer GMail SMTP test'; 
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__)); 
$mail->AltBody = 'This is a plain-text message body'; 
$mail->addAttachment('images/phpmailer_mini.png'); 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 

和關於HTML代碼..很多它是由腳本來完成的。基本上這主要思想是使用全HTML,我與模板

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>???</title> 
    <script src="../ckeditor.js"></script> 
    <script src="js/sample.js"></script> 
    <link rel="stylesheet" href="css/samples.css"> 
    <link rel="stylesheet" href="toolbarconfigurator/lib/codemirror/neo.css"> 
</head> 
<body id="main"> 


<form class="newsletter-signup" form action="http://??????gmail.php" method="post"> 
<main> 
     <div class="adjoined-top"> 
      <div class="grid-container"> 
       <div class="grid-width-100"> 
        <div id="editor"> 
        </div> 
       </div> 
      </div> 
     </div> 
</main> 


<input type="submit" class="btn btn-default btn-sand" value="subscribe"> 
</form> 
<button onclick="loadPages()">Click Me</button> 
<script> 
    function loadPages(){ 
     //document.getElementsByClassName('lulul')[0].setAttribute('src', "http://??????/gmail.php"); 
     document.getElementsByClassName('lulul')[0].setAttribute('name',"content"); 
    } 
</script> 
<script> 
    initSample(); 
</script> 

</body> 
</html> 
+0

你能告訴我們你的代碼嗎,所以我們可以幫助你正確,而不是基於假設? – Nirnae

+0

只要知道HTML代碼不會自動轉換成漂亮的HTML電子郵件。很少有電子郵件客戶端能夠正確支持所有的HTML,並且如果您也添加了CSS,則會遇到問題。寫適當的HTML的電子郵件是一個黑暗的藝術 - 不是真的那麼簡單的(至少如果你想要的工作跨客戶端) – junkfoodjunkie

+2

設置'$ MAIL-> IsHTML(真);' – Jer

回答

0

了正文以正確查看所有html輸出。下面是例子

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 
</head> 
<body bgcolor="#ffffff" text="#000000"> 
     This is the body text<br> 
<div class="moz-signature"><i><br> 
<br> 
The<br> 
Frenks<br> 
</i></div> 
</body> 
</html> 

這將在以正確的方式執行郵件正文內容:)

例如這將無法工作中HTML如果你會把眼前這個!

<b>The Frenks</b>