Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP mail attached file being clipped please help 1

Status
Not open for further replies.

afmiller

Programmer
Jan 23, 2005
5
US
I'm rather new to php but as an example, I'm using the below code to send out an attached .avi file through the mail function. However, when the avi arrives as an attachment to the email, it appears the first 57 bytes are gone (ie been stripped), whereas if i use outlook from my own computer and mail it to myself, i get the full avi file. Obviously I'm trying to understand what could be stripping out the first 57 bytes. Down in the code where it does the lines -

$encodedfile = chunk_split(base64_encode($attach));
echo $encodedfile;
echo "<br />";

I do see the echoing of the first 57 chars as they should be so at that point in the code it appears it's ok, the problem is somewhere afterwords during send or maybe even on the receive side from outlook.

Under much pressure here, any clues as to why????

Regards and Thanks

Alan

$boundary = '----'.md5(uniqid(rand())); # Boundary marker value
$mime = "MIME-Version: 1.0\n";
$stest1 = "\tboundary=".'"';
$mime .= 'Content-Type: '."multipart/mixed;\r\n\t";
$mime .= "boundary=".'"';
$mime .= "$boundary";
$mime .= '"';
$mime .= "\r\n"; */
$mime .= "Content-Type: multipart/mixed; ";
$mime .= "boundary=\"$boundary\"\n"; //'."\n\tboundary=\"$boundary\""."\n";
$mime .= "\n\nThis is a multiple part mime message\n\n";
$mime .= "--$boundary\n";
$mime .= 'Content-Type: '."text/plain;\n\tcharset=".'"iso-8859-1"'."\n";
$mime .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$bodystring = "This is body test.";
$mime .= "$bodystring\n";
$mime .= "--$boundary\n";
$mime .= "Content-Type: video/avi;\n\tname=\"$fattachname\"\n";
$mime .= "Content-Transfer-Encoding: base64\n";
$mime .= "Content-Disposition: attachment;\n\tfilename=".'"'."$fattachname".'"'."\n";
// now attachment
if(!($fattach = fopen($fattachname,'rb'))){
$error = "Can't open file";
echo $error;
exit;
}

$attach = fread($fattach,filesize($fattachname));
fclose($fattach);
$encodedfile = chunk_split(base64_encode($attach));
echo $encodedfile;
echo "<br />";
$mime .= $encodedfile;
$mime .= "--$boundary--";
mail($addresses, $esubject, "", $mime);
echo "You're email has been sent...";
 
If I had to guess, I'd say it's because you're not consistent in your line breaks. In some places you use "\n", in others "\r\n". You should use "\r\n" everywhere. With some mail servers and clients this does not matter, with others it does. But "\r\n" is the spec in the RFCs


When I see anyone trying to send complex emails from a PHP script, I always recommend the PHPMailer email class.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
thanks sleipnir214, i changed all to \r\n but same problem where first 57 bytes of attachment file is still not showing up in the received outlook email. However, took a look at the phpmailer class stuff and have a question perhaps you could answer.

in the first part of their tutorial they mention the following:

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.email.com"; // SMTP server

my question possibly hard to word but currently i use the basic php mail function and i understand that phpmailer class is replacing that, but it sounds like i must enter the above two lines and if i did a ini_get('SMTP') on my current site host it returns 'localhost'. if i utilize the phpmailer will it accept correctly and work with that string?

Regards and Thanks

Alan
 
On what platform are you running PHP? How is the email on that platform configured?


The SMTP transport uses sockets to communicate with a mail server. You may be better served using the sendmail or mail mailer types on unix-like OSes?

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
ok, i ran which returns all kinds of information about the server. In it, there is the line $ENV{SERVER_SOFTWARE} which shows:

Rapidsite/Apa/1.3.31 (Unix) FrontPage/5.0.2.2510 mod_ssl/2.8.17 OpenSSL/0.9.7c

Operating system under additional information says Irix.
 
I don't know what mail server IRIX runs. Stick with the SMTP transport for mail, I guess.

PHPMailer does not necessarily replace invoking mail() directly. It's a mostly a wrapper for mail() but adds some extras.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks for the tip on the PHPmailer, i implemented it and everything works fine now!

Best to ya!

ALAN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top