I am trying to send an email of my html page. This is the code I have so far:
<script language="javascript">
function emailCurrentPage() {
window.location.href = "mailto:?subject=" + document.title + "&body=" + encodeURI(document.location);
}
</script>
<button onclick="emailCurrentPage()">Email page</button>
Which sends the link of the current page but I want the whole html page shown in the email. Is there anyway of accomplishing this?
UPDATE and EDIT: So I have decided to try and go about this by using php since everywhere I look it seems impossible to accomplish with javascript. I know very little about php. Here is my code so far:
<?php
$to = 'john@example.com';
$subject = 'A test email!';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Put your HTML here
$message = file_get_contents('example.html');
// Mail it
mail($to, $subject, $message, $headers);
echo "Message Sent!"
}
?>
<form action="php/emailPage.php" method="post">
<input type="submit" name="submit" value="Email Page">
</form>
When I click the button all I get is the "Message Sent!" message but no email. I changed the "john@example.com" to my email but I do not receive an email in my inbox. Any ideas on what the problem is?