我可以使用smtpJS在我的网站上发送邮件。但是现在我想附加一个用jsPDF创建的新生成的 PDF ,我尝试了不同的方法,但它对我不起作用。有人认出我的问题吗?
我已在 functions.php 文件中将此链接添加到 WordPress。
wp_enqueue_script( 'pdfJS-js', get_stylesheet_directory_uri() . 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js', array( 'jquery' ),'',true );
但是在我的浏览器控制台中总是出现以下错误:
ReferenceError: 找不到变量:jsPDF
(var doc = new jsPDF('p', 'mm', "A4"); )
我的代码:
function sendMail() {
/* SmtpJS.com - v3.0.0 */
var Email = { send: function (a) { return new Promise(function (n, e) { a.nocache = Math.floor(1e6 * Math.random() + 1), a.Action = "Send"; var t = JSON.stringify(a); Email.ajaxPost("https://smtpjs.com/v3/smtpjs.aspx?", t, function (e) { n(e) }) }) }, ajaxPost: function (e, n, t) { var a = Email.createCORSRequest("POST", e); a.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), a.onload = function () { var e = a.responseText; null != t && t(e) }, a.send(n) }, ajax: function (e, n) { var t = Email.createCORSRequest("GET", e); t.onload = function () { var e = t.responseText; null != n && n(e) }, t.send() }, createCORSRequest: function (e, n) { var t = new XMLHttpRequest; return "withCredentials" in t ? t.open(e, n, !0) : "undefined" != typeof XDomainRequest ? (t = new XDomainRequest).open(e, n) : t = null, t } };
var receiverMail = document.getElementById('email').value;
var doc = new jsPDF('p', 'mm', "A4");
var elementHandler = {
'#ignorePDF': function (element, renderer) {
return true;
}
};
var source = window.document.getElementById("A4")[0];
doc.fromHTML(
source,
297,
210,
{
'width': 210,'elementHandlers': elementHandler
});
var base64 = doc.output("datauristring");
Email.send({
SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
To : receiverMail,
From : "name@example.com",
Subject : "Offerte von Name",
Body : "tst",
Attachments : [
{
name : "offerte.pdf",
data : base64
}]
}).then(
message => alert(message)
);
}