Jump to content

Recommended Posts

I have a project that I am working on where I need to take a snap shot from a webcam and send it via sms.

I have code to take the pic and code to send a text and they both work, but I cannot seem to combine the two to get the pic to send.

 

I would think that adding $result here

$formatted_number = $to."@vzwpix.com";
mail("$formatted_number", "SMS", "$message", "$result");  

would work, but it doesn't. (I am only concerned with verizon at the moment)

Here is entire php code:

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename = date('YmdHis') . '.jpg';
$result = file_put_contents( $filename, file_get_contents('php://input') );
if (!$result) {
	print "ERROR: Failed to write data to $filename, check permissions\n";
	exit();
}


$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $filename;
print "$url\n";
$from = $_POST['from'];
$to = $_POST['to'];
$carrier = $_POST['carrier'];
$message = stripslashes($_POST['message']);


if ((empty($from)) || (empty($to)) || (empty($message))) {
//header ("Location: sms_error.php");
}

else if ($carrier == "verizon") {
$formatted_number = $to."@vzwpix.com";
mail("$formatted_number", "SMS", "$message", "$result"); 
// Currently, the subject is set to "SMS". Feel free to change this.

//header ("Location: sms_success.php");
}

else if ($carrier == "tmobile") {
$formatted_number = $to."@tomomail.net";
mail("$formatted_number", "SMS", "$message");

// header ("Location: sms_success.php");
}

else if ($carrier == "sprint") {
$formatted_number = $to."@messaging.sprintpcs.com";
mail("$formatted_number", "SMS", "$message");

//header ("Location: sms_success.php");
}

else if ($carrier == "att") {
$formatted_number = $to."@txt.att.net";
mail("$formatted_number", "SMS", "$file_put_contents()");
//header ("Location: sms_success.php");
}

else if ($carrier == "virgin") {
$formatted_number = $to."@vmobl.com";
mail("$formatted_number", "SMS", "$message");

//header ("Location: sms_success.php");
}
?>

Thanks for any help.

 

-Sean

Link to comment
https://forums.phpfreaks.com/topic/287262-send-sms-webcam-snapshot/
Share on other sites

I would think that adding $result here . . . would work,

 

And, why would you think that? Did you verify what $result contains? Sorry, if I'm being a little rude, but if you had done even a modicum of due diligence you would have seen the fallacy of that assumption.

 

1) In the code $result is defined by the returned value of file_put_contents. If you had looked at that function in the manual you would see that the return value is

 

 

This function returns the number of bytes that were written to the file, or FALSE on failure.

So, I don't see how you would think that a number would be displayed as a picture.

 

2) You are then using $result in the mail function here:

 

mail("$formatted_number", "SMS", "$message", "$result");

The fourth parameter is for additional headers of the email - not for including attachments. You should probably look into something like PHPMailer instead of trying to code it yourself.

The reasoning behind my assumptions is that I am not a PHP coder and it seemed reasonable. I came here looking for some assistance, not to deal with some rude asshole who would rather make idiotic assumptions and bash people who are less knowledgeable instead of being helpful.

I really hope all new members are not treated this way.

 

Now, to anyone else:

It appears that everything needed to accomplish the goal is there, I just can't figure out how to put it all together.

Don't take things so personal. I did say

 

 

Sorry, if I'm being a little rude, but . . . 

 

I said that for a reason. I help a lot of people on these forums and I'm not going to waste my time trying to phrase things to not hurt peoples feelings. If I see a problem I will call it out. I will also call out something that the OP could have discovered themselves. For example, you state that you're not a PHP coder so it seemed reasonable. I don't follow that logic. If I am doing something I am not familiar with I will look at the documentation to see if I am doing it right. So, I called out the fact that simply looking at the manual for those two functions should have let you know right away that was not the way to accomplish what you wanted. The PHP manual is an excellent resource that I use all the time. I don't memorize every parameter and expected result.

 

As to your problem, I did provide a solution: use PHPMailer. It is a free class that makes sending emails much easier than trying to roll your own code. You can get it here: http://sourceforge.net/projects/phpmailer/

 

Attachments can be tricky and error prone. However, if you really feel like trying to code it yourself, along with having to debug it, then take a look at this page: http://webcheatsheet.com/php/send_email_text_html_attachment.php#attachment

 

 

Also, here is a forum post on another site with comments and example code both with using PHPMailer and with built-in PHP functions: http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail

I certainly do not take someone acting rudely as an insult, that would be the problem of the one being rude.

Anyway, 

I help a lot of people on these forums and I'm not going to waste my time trying to phrase things to not hurt peoples feelings

 

Maybe in the future you can choose to waste your (and my) time by just not responding if you are going to be a prick.

 

Now that that's over;

Being that I know very little about PHP, I did not realize that file_put_contents is a standard function. When I have programming-type issues, I have better results asking in places such as this as I find that when I RTFM, they are more geared towards those already in-the-know.

I am currently looking into PHPMailer, it seems like it will do what I need once I figure it out.

Question regarding AddAttachment() in PHPMailer:

With the image that gets generated with the webcam snapshot php, would the code be

$mail->AddAttachment($result)

The attachments are going to be code generated so each one will be different.

I am very very new to PHP, so if this is an absolutely idiotic and wrong answer, please forgive.

 

What you currently have now:

 

$message = stripslashes($_POST['message']);

 

Possible changes:

 

$result = file_get_contents('php://input');

 

$message = "Content-Type: image/jpg; name=\"picture.jpg\"\r\n"

  ."Content-Transfer-Encoding: base64\r\n"

  ."Content-disposition: attachment; file=\"picture.jpg\"\r\n"

  ."\r\n"

  .chunk_split(base64_encode($result))

  ."--1a2a3a--";

OrionSuperman,

Thanks for the assistance. When I ran your suggested code, this is what I got via text:

carrier=verizon&message=bvcv&Submit=Submit

Content-Type: image/jpg; name="picture.jpg"
Content-Transfer-Encoding: base64
Content-disposition: attachment; file="picture.jpg"

ZnJvbT0zMjEyOTIyMjkyJnRvPTMyMTI5MjIyOTImY2Fycmllcj12ZXJpem9uJm1lc3NhZ2U9YnZj
diZTdWJtaXQ9U3VibWl0
--1a2a3a--

Basically it sent me everything in the quotes.

http://tournasdimitrios1.wordpress.com/2011/11/18/sending-html-email-with-attachment-using-phps-mail-function/

This is where I pulled the code from. It looks like there was supposed to be a period before the = sign. As well (due to my extreme newness in PHP) there were some other variables set that may be relevant to fixing the code. I hope this helps!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.