Jump to content

[SOLVED] Email w/ attachment script sends 2+ email in firefox, 1 in IE?


Recommended Posts

I finally got my printscreen and email php script to work, but it only works properly in IE.  In firefox, it gives me an error (i'm on my fiancee's mac who has Firefox in Slovak langauge, so can't read), and sends 2-4 emails.  In IE, it works correctly, sends only 1 email, and displays the echo statements.  Here's the code, below the "imagegif" area is the email function, above that is the image compiler.

 

<?php

error_reporting(0);
/**
* Get the width and height of the destination image
* from the POST variables and convert them into
* integer values
*/
$w = (int)$_POST['width'];
$h = (int)$_POST['height'];

// create the image with desired width and height

$img = imagecreatetruecolor($w, $h);

// now fill the image with blank color
// do you remember i wont pass the 0xFFFFFF pixels 
// from flash?
imagefill($img, 0, 0, 0xFFFFFF);

$rows = 0;
$cols = 0;

// now process every POST variable which
// contains a pixel color
for($rows = 0; $rows < $h; $rows++){
// convert the string into an array of n elements
$c_row = explode(",", $_POST['px' . $rows]);
for($cols = 0; $cols < $w; $cols++){
	// get the single pixel color value
	$value = $c_row[$cols];
	// if value is not empty (empty values are the blank pixels)
	if($value != ""){
		// get the hexadecimal string (must be 6 chars length)
		// so add the missing chars if needed
		$hex = $value;
		while(strlen($hex) < 6){
			$hex = "0" . $hex;
		}
		// convert value from HEX to RGB
		$r = hexdec(substr($hex, 0, 2));
		$g = hexdec(substr($hex, 2, 2));
		$b = hexdec(substr($hex, 4, 2));
		// allocate the new color
		// N.B. teorically if a color was already allocated 
		// we dont need to allocate another time
		// but this is only an example
		$test = imagecolorallocate($img, $r, $g, $b);
		// and paste that color into the image
		// at the correct position
		imagesetpixel($img, $cols, $rows, $test);
	}
}
}

// print out the correct header to the browser
//header("Content-type:image/jpeg");
// display the image
    header("Content-type: image/gif");
imagegif ($img,"images/temp2.gif");
echo 'hello world';



$fileatt = "images/temp2.gif"; // Path to the file
$fileatt_type = "image/gif"; // File Type
$fileatt_name = "temp2.gif"; // Filename that will be used for the file as the attachment

$email_from = "trevorfayas@sonicandpals.com"; // Who the email is from
$email_subject = "Soap Shoe Pic"; // The Subject of the email
$email_txt = "Hi, here it is"; // Message that the email has in it

$email_to = "trevorfayas@sonicandpals.com"; // Who the email is too

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);
echo 'email code sent';
if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}

?>

 

Any ideas why firefox is reading the code so differently?  Or how to fix this?  I can't find much in google or searching the forums, other than IE and firefox can have differnet results with php

Okay, i firstly put a $ok for the image creation and an if statement, that fixed the multiple email.

 

I did the post thingy, it gave me this a HUGE string of the ff0000 (the image is a red rectangle), other than that it gave me "[rows] => 100 [cols] => 0 [height] => 100 [width] => 200 ) hello worldemail code sentThe file was successfully sent!"

 

Still can't figure out why it's giving an error message, can anyone figure it out?

 

It may have to do with a special code that was put it to remove FFFFFF (black pixels, since they can't send from flash). 

could that be the problem?  I even removed the black lines (since there is a special part of the code that takes the "0" which are sent out as black pixels and corrects them).

 

It's not the black pixel part, why does firefox constantly give an error on displaying and won't send any of the echo outs?  The only error i'm getting with the script with error_report(); (reset to give errors) is a minor undefiend variable in line 91 :-/

Figured it out, did some cutting apart of the code to see what was causing the problem, it was the

    header("Content-type: image/gif"); 

 

Last question though, i'm still getting this error:

 

Notice: Undefined variable: email_message in /home/sonicand/public_html/soaps/printscreen/files/pixels.php on line 91

 

Notice: Undefined variable: email_message in /home/sonicand/public_html/soaps/printscreen/files/pixels.php on line 91

 

Any idea why it's cuasing the error, i can't figure it out.  What's wrong with the code that it's cuasing an error?

change

 

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

 

to

$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

 

Note the removed dot "$email_message = "

 

as this is the first time your setting it

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.