简体   繁体   English

使用PHP通过电子邮件发送动态创建的html内容

[英]Sending dynamically created html content through email with PHP

I'm making a simple todo list: http://jsbin.com/pemeqeni/1/edit?html,output 我正在制作一个简单的待办事项清单: http : //jsbin.com/pemeqeni/1/edit?html,输出

I want to be able to email myself the list, and I'm wondering how to do this with PHP specifically. 我希望能够通过电子邮件将列表发送给自己,并且我想知道如何使用PHP来做到这一点。 I thought about scraping the HTML with DOMdocument, but I think that will only get the content from the static HTML page, which will never have list items. 我曾考虑过使用DOMdocument刮擦HTML,但是我认为那只会从静态HTML页面获取内容,而该页面永远不会包含列表项。 My other idea is to dynamically create a bunch of hidden input fields in the emailForm and dynamically delete them just as I do with the list items. 我的另一个想法是在emailForm中动态创建一堆隐藏的输入字段,并像删除列表项一样动态删除它们。 Are there any other options? 还有其他选择吗? What's the standard protocol for something like this? 这样的标准协议是什么?

Something like this should work for getting all list elements. 这样的事情应该可以获取所有列表元素。

<script>
function getEachListElement() {
   var testList = document.getElementsByClassName("todoBody");
   for (var i = 0; i < testList.length; i++) {
       document.writeln(testList[i].innerHTML);
   }
}
</script>

Try it out by changing your form action to this 通过将表单操作更改为此来尝试

<form name="emailForm" method="GET" action="JavaScript:getEachListElement()">

Then you can just create a string that you pass to PHP to email to yourself. 然后,您只需创建一个字符串,然后将其传递给PHP以通过电子邮件发送给自己。

Have you tried the php mail function? 您是否尝试过php邮件功能?

ie

<?
mail( $email, $subject , $text );
?>

Instead of get I would use post then set up a php script you call where you put your values(strings) into variables using $_post and use the mail function to mail those variables(strings). 而不是得到我会使用post然后设置一个php脚本,您调用该脚本,在其中使用$ _post将值(字符串)放入变量中,然后使用mail函数将这些变量(字符串)邮寄出去。

just to be more clear your html would look like this 只是为了更清楚您的html看起来像这样

<form name="emailForm" method="POST" action="getContent.php">
                <input type="text" name="email" value="email"><input type="submit" value="send">
            </form>

Your getContent.php would then look like this 您的getContent.php将如下所示

<?

$myemail = "myemail@tada.com";
$email = $_POST["email"];

mail ($myemail, 'The shiz you wanted', $email);

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM