Author Topic: HTML <div> sent by email in PHP  (Read 7716 times)

Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
HTML <div> sent by email in PHP
« on: October 17, 2015, 19:27 »
Does anyone knows how to code this?

So, I have a <div> in my html page that grabs some content with javascript variables. I need to make a PHP script that send that content in a email.

I found out on internet that I need to make a jQuery script that sends my content to the PHP script wich emails it.

This is a part of my content:
Code: [Select]
<div id="content">
<meta charset="UTF-8">
<table border=”1″ style=”width:1000px”>
<tr >
<td class='myclass'><b>Nume:</b><span id='nm'></span>, <span id='pm'> </span><b> Vârsta:</b><span id='demo'></span> <b>Sex:</b><span id='sx'></span> <b>Data:</b> <span id='time'></span></td>
</tr>
</table>
<table border=”1″ style=”width:1000px”>



<tr>
    <td><b>Somatizare</b></td>
    <td><b>Obsesiv/<br>Compulsiv</b></td>
...
    <content> <content> <content>
...

<span id='showipI'></span> <br><br>
<span id='showpsiI'></span> <br><br>
<span id='showdom'></span><br><br>
</p>
       
 </div>

This is my PHP script:

Code: [Select]
<?php

  $to 
"my_email_acc";
  
$subject "HTML Data";
  
$message $_POST["content"];
  
$headers "From: The Server <server@doe.com>" "\r\n" .
             
"Content-type: text/html" "\r\n";

  
mail($to$subject$message$headers);

?>

jQuery script ??
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #1 on: October 17, 2015, 19:36 »
Code: ("javascript") [Select]
var some_status_element = $('#status'),
content = $('#content');
function send_a_deer() {
$.post({
url:'path/to/yourmegaphpscript.php',
type:'post',
data: {content: content.html()},
beforeSend: function() {
some_status_element.html('loading...');
},
success: function() {
some_status_element.html('done!');
},
error: function() {
some_status_element.html('deered. error happenederedeered');
}
})
}

Something like this
mby i got some syntax errors, coz woke up and typed code right in this lil message input box
but logics is right
//go create some element with id 'status', empy one

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #2 on: October 17, 2015, 19:39 »
But ur task is so bad
u should just send some important unique variables from js, not whole email body (try to never deer with user internet traffic, pls :s, send as less data as u can. And do response with less data)
And generate that 'html structure' in PHP again before emailing;
also purify these from some random stuff
at least with htmlspecialchars() function



Veri bed, renovatio, veri bed.

Spoiler for Hiden:
dir english
The mini deer goes here.

Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
Re: HTML <div> sent by email in PHP
« Reply #3 on: October 17, 2015, 20:22 »
There are to many variables, about 20 and I want them displayed in a complex table. I'm not quite a coder master. I needed to make some questionnaires and I made them  using only documentation found on net.

I've pasted your code in:

Code: [Select]
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
here
</script>

I've replaced path to PHP script but I don't know what element you need me to create.
Do I send the content to PHP script by using <form name="name" method="post" action="myscript.php"> and submit button or I need to call your function too?
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
Re: HTML <div> sent by email in PHP
« Reply #4 on: October 18, 2015, 11:38 »
I did it!

Code: [Select]
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){

  $('#sendEmail').click(function(){
     $.ajax({
         type: 'POST',
         url: 'http:mydomain/etc/send_form_email.php',
         data: { content: $('#email-data').html()}
     });
  });

});
</script>

Code: [Select]
<div id="email-data">
    <div id="content">
my content
     </div>
</div>

<a href="#" id="sendEmail" >Send Email</a>

Ty dude!  :)
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
Re: HTML <div> sent by email in PHP
« Reply #5 on: October 18, 2015, 12:55 »
I need help again.

My div content is hidden and when I send it via email with my php script is still hidden.
How do I code the php script to dispay my div in email?

Code: [Select]
<div id="content" style="visibility:hidden">
Code: [Select]
<?php

  $to 
"admin@mail.com";
  
$subject "Rezultate chestionare";
  
$message $_POST["content"];
  
$headers.= "Content-Type: text/html;charset=utf-8\r\n";
        

  
mail($to$subject$message$headers);

?>

I think this piece of code should be added to php script to dispplay it but I don;t know where to put it.

Code: [Select]
<script type=\"text/javascript\">document.getElementById('".$content."').style.display = 'block';</script>
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #6 on: October 18, 2015, 14:20 »
You deer can replace this stuff
Code: [Select]
data: {content: content.html()},with this
Code: [Select]
data: {content: content.clone().css('display', 'block').html()},But it sucks

better do it on php side (but it sucks too):
Code: [Select]
$message = str_replace('id="content" style="visibility:hidden"', 'id="content"', $_POST['content']);



Also i'd  like to show u some example:
Some lil kid called hacker (lets call him Ayd.Mev) will use this stuff in google chrome console (actually he should send raw request from something else, but no, he's lil kid called hacker):
Code: [Select]
$.ajax({
         type: 'POST',
         url: 'http:mydomain/etc/send_form_email.php',
         data: { content: 'Hahaha disregard that, i suck cocks! (c) [some hard porn pic here]'}
     });
And ull get excactly what Ayd.Mev sent to u instead of your lil #content


So if u're coding some serious stuff, i might waste some time to explain how do things work, ask mi, dir helps



Also in PHP in places where u're using strings, like $_POST['content'], dont use double quotes, use these ' stuffs. It will decrease execution time
U should use double quotes in php only when you are deering some variable in some string, e.g. : $_POST["deer_prefix_$variable"]. Php engine will replace $variable with value of $variable here. If ull use just ' this stuff, php engine will ignore anything and interprete it as string

Also u should use your little double quotes when u have to insert some special symbol (like \n, \r, \t and so on), use "\n" for these


Deers!

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #7 on: October 18, 2015, 14:22 »
btw u got 2 errors in ur php code
remind me later to explain and teach you some little things

Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
Re: HTML <div> sent by email in PHP
« Reply #8 on: October 18, 2015, 15:41 »
I've made this:

Code: [Select]
<?php

  $to 
'my_mail';
  
$subject 'Rezultate chestionare';
  
$message str_replace('id="content" style="visibility:hidden"''id="content"'$_POST['content']);
  
$headers.= 'Content-Type: text/html;charset=utf-8"\r\n"';
        

  
mail($to$subject$message$headers);

?>

It works now.

About errors: do you reffer at "from"? It says "no from address" when I open the email.
I have input type=email in my form. I got it's value in a variable and then displayed it innerhtml, with <span>, in my <div> content. So I can see it in the emai I recieve but not as "from" in header.

Another problem. I have 2 buttons:1 for sending the content to php script, and another one that computes my form. The form needs computing before it gets send to email, because the <div> content is the form's results.

Computing form:
Code: [Select]
<input id="btnClickMe"
        type="button"
        value="Am terminat"
        onclick=computeForm(this.form) />
Sending to php script:
Code: [Select]
<a href="#" id="sendEmail" >Send Email</a>
Can I merge this 2 in one button?
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #9 on: October 18, 2015, 17:35 »
http://php.net/manual/ro/function.mail.php
Example #2 for from
You can export this email in javascript from that lil innerhtml and send it like this:
   data: { content: $('#email-data').html(), email: some_email_variable_here}
then get it with $_POST['email'] and validate it with http://php.net/manual/ro/filter.examples.validation.php example from here


About your buttons
Never motherdeering use 'onclick' in html structure
Since u have jQuery, use some $('selector').on('click', function() { /* DEER STUFF */ });

I should know how does calculateForm work
If its sync function, u can just call it like this:
Code: [Select]
  $('#sendEmail').click(function(){
computeForm();
$.ajax({
         type: 'POST',
         url: 'http:mydomain/etc/send_form_email.php',
         data: { content: $('#email-data').html()}
     });
});

And delete this useless this.form from argument
Find that form with selector or document.getElement... right in function computeForm
Actually u should create some variable in script scope, like var form = document.getElement...;
then use this 'form' variable in function



About errors:
no, you have this string in code
Code: [Select]
  $headers.= "Content-Type: text/html;charset=utf-8\r\n";thats veri bed, Renovatio, veri bed.
Dont use '.=', '*=', '+=' and other stuff if you didnt set variable before
Cause it will generate error and waste some system resources
If you did never set this $headers, use just '=' then;

Also use single quotes as i said before, instead of double ones in $to and $subject strings



Im sick a bit and if i failed my english hard here, inform me, so ill rewrite these explanations better



p.sp btw in 1st ur post you have nice From: header without this error, cause u didnt use lil .= operator




Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
Re: HTML <div> sent by email in PHP
« Reply #10 on: October 18, 2015, 21:43 »
I solved that error, now I got "from". I used single quotes. With email it didn't worked but is not to important, anyway. That content is sent to my email, not to users, I get their email address in div content, in case I want to send them their form results.

Important is not to make them click 2 buttons because if 1 isn't clicked the other one is clicked for nothing. This is my last problem, the rest looks fine.

I've called the form function like this: $('#sendEmail').click(function(){
computeForm();
but it didn't worked, actually I didn't recieved mail after doing this.
I've deleted this.form and the form didn;t compute itself after that.

My form function is kinda messed up. Is very very big and unnecesary complicated but it works. It looks something like this:

Code: [Select]
<script type="text/javascript">
function test_it(entry) {
if (entry.value!=null && entry.value.length!=0) {
entry.value=""+ eval(entry.value);
}
computeForm(entry.form);
}
function computeForm(form) {
var sos=0
var som=0
declaring more variable etc etc


calculating my form factors

for (var count=0; count<5; count++)
{
if (form.i1[count].checked){
var som=som+parseInt(form.i1[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.i4[count].checked){
var som=som+parseInt(form.i4[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.i12[count].checked){
var som=som+parseInt(form.i12[count].value);
}
}
etc etc

calculating percentage of some answears (my form items have 5 options each)

for (var count=0; count<5; count++)
{
if (form.i4[count].checked && parseInt(form.i4[count].value)==4){
var strp=strp+1;
} else if (form.i4[count].checked && parseInt(form.i4[count].value)==3) {
var strr=strr+1;
}
}

for (var count=0; count<5; count++)
{
if (form.i5[count].checked && parseInt(form.i5[count].value)==4){
var strp=strp+1;
} else if (form.i5[count].checked && parseInt(form.i5[count].value)==3) {
var strr=strr+1;
}
}

for (var count=0; count<5; count++)
{
if (form.i6[count].checked && parseInt(form.i6[count].value)==4){
var strp=strp+1;
} else if (form.i6[count].checked && parseInt(form.i6[count].value)==3) {
var strr=strr+1;
}

etc etc

setting standard values for some factors in condition to user's sex and age.

if (document.getElementById("vn").value < 20 && s==0) {
somD=0.75
somDD=1.58
} else if (document.getElementById("vn").value >= 20 && s==0) {
somD=0.75
somDD=1.49
} else if (document.getElementById("vn").value < 20 && s==1) {
somD=0.33
somDD=0.92
} else if (document.getElementById("vn").value >= 20 && s==1) {
somD=0.42
somDD=1.08
}

etc etc etc

calculating global factors

GSI=(som + oc + sip + dep + anx + om + af + ip + psi) /90
PSDI=(som + oc + sip + dep + anx + om + af + ip + psi)/stru

etc etc

setting text as interpretation for factors values

if (PSDI>=psdiDD && PSDI < 3) {
psdiI="Intesitatea simptomelor depăsește limita normală și respondentul indică o suferință psihică reală."
} else if (PSDI >= psdiD && PSDI < psdiDD ) {
psdiI="Intensitatea simptomelor este semnificativă și indică probabilitatea unei suferințe psihice."
} else if (PSDI < psdiD) {
psdiI="Intensitatea simptomelor se află în limite normale."
} else if (PSDI>=3) {
psdiI="Intensitatea simptomelor a depășit cu mult limita normală și, cel mai probabil, respondentul prezintă o suferință psihică agravată."
}

etc etc etc

getting those variables in innerhtml

document.getElementById('showsomM').innerHTML = somM;
document.getElementById('showocM').innerHTML = ocM;
document.getElementById('showsipM').innerHTML = sipM;
document.getElementById('showdepM').innerHTML = depM;

etc etc etc

}
</SCRIPT>

After that comes the form:

Code: [Select]
<form METHOD=POST>

with input type text, number, email and the rest of it (91 items) radio.

<center><div><input id="btnClickMe"
        type="button"
        value="Am terminat"
        onclick=computeForm(this.form) />
 </div></center>

</form>
</body>

And after that comes the hidden div with form variables displayed via <span>

You helped me a lot so is ok if you can't help me with this problem too. Ty deer!  ;D
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #11 on: October 19, 2015, 00:45 »
but u didnt declare that form variable in script scope -_-
where is
var form = document.getElement.... ?
also u didnt delete (form) from function arguments :s

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #12 on: October 19, 2015, 00:45 »
im ingame and cant explain stuff:D

Offline Renovatio

  • Retired Moderator
  • HolyShit Member
  • *
  • Topic Author
  • Posts: 7440
  • Country: ro
  • Karma: +811/-317
  • Server Account: -Renovatio.
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards 2nd place on GFX Ladder 2015 [UNIQUE] B&U staff member [RARE] Winner of 3 Challenges of the Week [RARE] Winner of 10 Signature of the Week Contest [LEGENDARY] GFX Tournament Winner [UNIQUE] Forum staff member [RARE] 1st place on GFX Ladder 2018 [UNIQUE] Winner of 10 Photo Manipulation Contest [LEGENDARY] Making 50 bets in Footbal Betting [COMMON] Violinist - Music Quiz #1 [EPIC] 1st place on GFX Ladder 2017 [UNIQUE] Winner of 15 Photoshop Challenge Contests [LEGENDARY] Tournaments Contribution [RARE] Jungle Race Tour Winner [RARE] Uther Party Tournament Winner [COMMON] 1st place on GFX Ladder 2016 [UNIQUE] GFX staff member [RARE] 2nd place in Special Event #2 [UNIQUE]
    • View Profile
    • Awards
Re: HTML <div> sent by email in PHP
« Reply #13 on: October 19, 2015, 12:08 »
I did it. Is working now.  ;D

I didn't knew how to declare form's variable because it didn't had an ID.

I deleted this part:
Code: [Select]
function test_it(entry) {
if (entry.value!=null && entry.value.length!=0) {
entry.value=""+ eval(entry.value);
}
computeForm(entry.form);
}
I don't know if was important or not.

I deleted form from function arguments.
I've placed an ID for my form:
Code: [Select]
<form id="form" METHOD=POST>and I modified my jQuery script like this:

Code: [Select]
$(document).ready(function(){
var sform = document.getElementById("form").innerHTML;
  $('#sendEmail').click(function(){
   computeForm(sform);
     $.ajax({
         type: 'POST',
         url: 'http://chestionare.byethost12.com/wp/send_form_email.php',
         data: { content: $('#email-data').html()}
     });
  });

});
</script>

Tnx, dude. I couldn't do it without you.
Join GFX Competitions. Awards, titles, acces to private forum areas and more are given. Is fun.

guest49825

  • Guest
Re: HTML <div> sent by email in PHP
« Reply #14 on: October 20, 2015, 00:51 »
Thats cute
And most cute part here is u did it urself, i only sent u right way and didnt explain whole stuff; So u learn some deer things