admin管理员组文章数量:1391811
Is it possible to take the content that is under a specific <div>
and email that content?
For example: If I have something like this:
<div id="1">
<ul>
<li>a</li>
<li>b</li>
<ul>
</div>
Basically I want to just reference <div>
and take the whole content and email it.
is there any way to cache the contents in the div?
Is this anyway possible? ( javascript? php?)
Thanks.
Is it possible to take the content that is under a specific <div>
and email that content?
For example: If I have something like this:
<div id="1">
<ul>
<li>a</li>
<li>b</li>
<ul>
</div>
Basically I want to just reference <div>
and take the whole content and email it.
is there any way to cache the contents in the div?
Is this anyway possible? ( javascript? php?)
Thanks.
Share Improve this question asked Dec 1, 2009 at 17:43 JProJPro 6,55613 gold badges59 silver badges85 bronze badges 2- It can be done on server side. – Ivan Nevostruev Commented Dec 1, 2009 at 17:48
- You might have just done this for the example, but the first character of ID shouldn't be a number. As per the W3C spec, it should be in [a-zA-Z]. This could potentially lead to issues with some of the solutions below. – John McCollum Commented Feb 13, 2010 at 12:22
2 Answers
Reset to default 6It really depends on what further requirements you have. You could have a jQuery script send the contents to a PHP script, which then emails them out:
$.post("email.php", { data : $("div#1").html() }, function(result){
/* handle results */
});
And then your email.php script looks similar to the following (Don't use the following code as-is):
<?php
$to = "[email protected]";
$subject = "HTML Data";
$message = $_POST["data"];
$headers = "From: The Server <[email protected]>" . "\r\n" .
"Content-type: text/html" . "\r\n";
mail($to, $subject, $message, $headers);
?>
As stated above, jQuery is probably the easiest way for you. You can add jQuery to your page with the following line:
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.3.2/jquery.min.js"></script>
You can also reference your content by using just $('#1').html(), or whatever the ID of your div is (in your example, it's 1).
本文标签: javascriptemail div content in phpStack Overflow
版权声明:本文标题:javascript - email div content in php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744770517a2624309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论