Jump to content

How to email a screenshot to myself using PHP


simora

Recommended Posts

I'm using this code from here :

http://talkerscode.com/webtricks/take-screenshot-of-a-webpage-using-html5-and-javascript.php

to capture a Screeenshot of my Web Page.

I'm on Windows 7, and I already have Javascript & PHP code which already captures the Web Page Screenshot.

What I'm trying to do is to modify the PHP code to automatically eMail me a copy of the screenshot.

How can I add PHP code to email the captured screenshot to myself.

Thanks

Link to comment
Share on other sites

Uh,  where does this code of yours place the screenshot?

 

I've got it to post the screenshot to the active directory.

Is there a  way to attach the file if  the filename is in  this format like;

$file = md5(uniqid()) . '.png';

 

Ideally,  I'll like to append  the Time to  the  beginning of  the Filename.

 

Thanks

Link to comment
Share on other sites

So - you're saying that the screenshot is already up on the server where your php script can do whatever it wants with it?  

 

So - what's the hangup?  

 

You've got a file so create an email and attach the file to it and send it off.  

 

Try looking at the PHP manual and read up on mail() and just do it.  Of course a better choice is what Jacques said - PhpMailer is a pretty good email package.

Link to comment
Share on other sites

Sending attachments with mail() is going to be a major PITA, because you'll have to manually assemble a multipart message.

 

PHPMailer, on the other hand, does exactly what you want with the addStringAttachment() method:

$mail->addStringAttachment($image_content, $filename);

I don't understand why you would want to choose a cryptic MD5-based name, though. This is an e-email attachment. Why not choose a meaningful name, so that you can properly store the file on your PC?

Link to comment
Share on other sites

Sending attachments with mail() is going to be a major PITA, because you'll have to manually assemble a multipart message.

 

PHPMailer, on the other hand, does exactly what you want with the addStringAttachment() method:

$mail->addStringAttachment($image_content, $filename);

I don't understand why you would want to choose a cryptic MD5-based name, though. This is an e-email attachment. Why not choose a meaningful name, so that you can properly store the file on your PC?

Thanks:   I  didn't realize  that using Mail()  would be such an issue.  I'll check out PhP Mailer as everyone has suggested. 

BTW: The image is that of a Form.  How can I post a field from the form along with the image so that I can use  that form field as the filename ?      ex :  $email

Link to comment
Share on other sites

How are you getting the file uploaded?  Via an html 'file' input element?  If so then be sure to capture any other data item you want to grab.

Not quite sure how to do this.

I'm using a html 'file' input and below is the function that I'm using to send the image to the php. What I'm looking for is a way to modify the function so  that it also sends the html inputs to the php so that I can use them for the email.  Here's  the function code:

function take_screenshot()
{
 html2canvas(document.body, {  
  onrendered: function(canvas)  
  {
    var img = canvas.toDataURL()
    $.post("save_screenshot.php", {data: img}, function (file){
    window.location.href =  "save_screenshot.php?file="+ file
    });
  }
 });
}
Link to comment
Share on other sites

How much coding do you do?  You have this javascript that you are apparently familiar with but you don't seem to know what to do with it to add another input field.  Or do you just want us to write it for you?  Why are you even doing this with JS anyway?  It is normally a pretty simple php process to upload a file and some related info.  Or haven't you done any research on that either?

 

It's funny how so many people who don't know a thing about programming just suddenly think that they can copy something and make it do tricks for them and when they want to add to it (which every programmer ends up doing!) they think that people are just hanging out on the web waiting to jump right to it.

 

Admit it - if you don't know diddly about this technology stop trying to lead us to believe that you do.  And if actually do know anything at all show us what you are trying to do and ask us for help.  So far I'm leaning on option #1 and you won't get far on this site with that attitude.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.