2017-04-14 63 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>