开发者

email div content in php

开发者 https://www.devze.com 2022-12-13 03:25 出处:网络
Is it possible to take the content that is under a specific <div> and email that content? For example:

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>
&开发者_Go百科lt;/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.


It 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 = "john@doe.com";
  $subject = "HTML Data";
  $message = $_POST["data"];
  $headers = "From: The Server <server@doe.com>" . "\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.com/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).

0

精彩评论

暂无评论...
验证码 换一张
取 消