Reputation: 139
I'm having a php page which is a dynamically generated ticket page and I've added a button to print the ticket content. Here is an example
<html>
<body>
<div id="ticket-div">
<table><?php here goes the contents of ticket ?></table>
</div>
<button>Print this ticket</button>
<button>Email Ticket</button>
</body>
</html>
And I wonder how to specify only the div contents in mail function that I use.
<?
if(($Content = file_get_contents("ticket.php")) === false) {
$Content = "";
}
$Headers = "MIME-Version: 1.0\n";
$Headers .= "Content-type: text/html; charset=iso-8859-1\n";
$Headers .= "From: ".$FromName." <".$FromEmail.">\n";
$Headers .= "Reply-To: ".$ReplyTo."\n";
$Headers .= "X-Sender: <".$FromEmail.">\n";
$Headers .= "X-Mailer: PHP\n";
$Headers .= "X-Priority: 1\n";
$Headers .= "Return-Path: <".$FromEmail.">\n";
if(mail($ToEmail, $Subject, $Content, $Headers) == false) {
//Error
}
?>
what I want is , just attach the contents of div "ticket-div" in an email so that the customer can download it from his mail.
Thanks in advance
Upvotes: 1
Views: 1354
Reputation: 4275
You need to use javascript for this purpose and specify the headers.use the code below
<?php
if($_GET['email']){
$to = "[email protected]"; // Write the email here
$from = '[email protected]'; // Write your email here
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "
<div id='ticket-div'>
<table>here is the content of the ticket</table>
</div>
";
mail($to, $subject, $message, $headers);
}
echo $message = "
<div id='ticket-div'>
<table>here is the content of the ticket</table>
</div>
";
?>
<button onclick='window.print();'>Print this ticket</button>
<form action='url to this file.php' method='POST'>
<input type='submit' name='email' id='button'>Email Ticket</button>
</form>
The code above can take some time but it will deliver your mail for sure.
I made a script of what you wanted , download it from this url wpbrisk.com/download/email/email/email.zip
. Or you can try the demo out by visiting this url
http://wpbrisk.com/download/email/email/index.php?email_addr=YOUR_EMAIL_ADDRESS_HERE
I was working for this script the whole eve and will be writing an article on my site http://hangupin.com . Be sure to read it Hope this helps you
Upvotes: 1