From: "Gary" on
I am trying to have an attachment to an email from a form. Email is working
fine, am unable to get attachment. The attachment will be a word.doc.

I am getting error message

Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
failed to open stream: No such file or directory in
/home/oneonel1/public_html/emailreminderresult.inc.php on line 24
Mail failed

Line 24 reads:

$attachment =
chunk_split(base64_encode(file_get_contents('attachment.zip')));

here is the all of the code that I have removed the email addresses & such.

Can someone point me in the right direction?

Thank you

Gary

<?php
$fname=stripslashes($_POST['fname']);
$lname=stripslashes($_POST['lname']);
$email=stripslashes($_POST['email']);
$comments=stripslashes($_POST['comments']);
$ip= $_SERVER['REMOTE_ADDR'];
$attachment = $_POST['attachment'];

$attachment = $_FILES['attachment']['name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_size = $_FILES['attachment']['size'];

//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: myemail\r\nReply-To: myemail.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed;
boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment =
chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 24
//define the body of the message.
ob_start();

//Turn on output buffering

//--PHP-mixed-
echo $random_hash;
//Content-Type: multipart/alternative; boundary="PHP-alt-
echo $random_hash;

//--PHP-alt-
echo $random_hash;

/* Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit */



//--PHP-alt-
echo $random_hash;
/* Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit */


//--PHP-alt-

echo $random_hash;

//--PHP-mixed-


echo $random_hash;

/* Content-Type: application/zip; name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment */

echo $attachment;
//--PHP-mixed-

echo $random_hash;


//copy current buffer contents into $message variable and delete current
output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print
"Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";



echo "Thank you for contacting <b>888!</b><br /><br />";
echo "You have submitted the following information:<br /><br />";
echo "Name: $fname $lname<br />";
echo "E-Mail Address: $email<br />";
echo "Your comments or request: $comments<br /><br /><br />";




echo "We have also sent you an e-mail to $email with the submitted
information as well as our contact information for your convienience. <br
/><br />
Thank you for the opportunity to serve you!";


/*This is the email message to submitter*/
$contact="888\n 888\n 888";
$from_d="$email";
$to_d="$email";
$subject_d='Thank you from 888';
$msg_d="Thank you $fname for your submission, find our contact information
listed for your convenience.\n\n"
.."$contact\n\n"
.. "You have submitted the following information\n\n"
.. "Name: $fname $lname \n"
.. "E-Mail Address: $email\n"
.. "Comments: $comments\n"
;
mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);


/*this is to form owner, */
$from="$email";
$to="myemail";
$subject="Submission from 888";
$msg= "This is a submission from 888com. \n\n"
.. "Clients Name: $fname . $lname \n"
.. "Email Address: $email\n"
.. "Comments: $comments\n"
;


mail($to, $subject, $msg, 'From:' .$from);

?>



__________ Information from ESET Smart Security, version of virus signature database 5228 (20100625) __________

The message was checked by ESET Smart Security.

http://www.eset.com




From: Richard Quadling on
First of all, take a look at
http://docs.php.net/manual/en/features.file-upload.php

You are trying to open a named file (attachment.zip), but that may not
be what was uploaded.

The 2 main functions to get to grips with are ...

is_uploaded_file() and move_uploaded_file().

Uploaded files are not best directly accessed. Instead they should be
moved from the temp directory (assuming the server is set to
temporarily store uploaded files there) to a proper location for use
later on in the script.

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
From: Ashley Sheridan on
On Fri, 2010-06-25 at 09:51 -0400, Gary wrote:

> I am trying to have an attachment to an email from a form. Email is working
> fine, am unable to get attachment. The attachment will be a word.doc.
>
> I am getting error message
>
> Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
> failed to open stream: No such file or directory in
> /home/oneonel1/public_html/emailreminderresult.inc.php on line 24
> Mail failed
>
> Line 24 reads:
>
> $attachment =
> chunk_split(base64_encode(file_get_contents('attachment.zip')));
>
> here is the all of the code that I have removed the email addresses & such.
>
> Can someone point me in the right direction?
>
> Thank you
>
> Gary
>
> <?php
> $fname=stripslashes($_POST['fname']);
> $lname=stripslashes($_POST['lname']);
> $email=stripslashes($_POST['email']);
> $comments=stripslashes($_POST['comments']);
> $ip= $_SERVER['REMOTE_ADDR'];
> $attachment = $_POST['attachment'];
>
> $attachment = $_FILES['attachment']['name'];
> $attachment_type = $_FILES['attachment']['type'];
> $attachment_size = $_FILES['attachment']['size'];
>
> //create a boundary string. It must be unique
> //so we use the MD5 algorithm to generate a random hash
> $random_hash = md5(date('r', time()));
> //define the headers we want passed. Note that they are separated with \r\n
> $headers = "From: myemail\r\nReply-To: myemail.com";
> //add boundary string and mime type specification
> $headers .= "\r\nContent-Type: multipart/mixed;
> boundary=\"PHP-mixed-".$random_hash."\"";
> //read the atachment file contents into a string,
> //encode it with MIME base64,
> //and split it into smaller chunks
> $attachment =
> chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 24
> //define the body of the message.
> ob_start();
>
> //Turn on output buffering
>
> //--PHP-mixed-
> echo $random_hash;
> //Content-Type: multipart/alternative; boundary="PHP-alt-
> echo $random_hash;
>
> //--PHP-alt-
> echo $random_hash;
>
> /* Content-Type: text/plain; charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit */
>
>
>
> //--PHP-alt-
> echo $random_hash;
> /* Content-Type: text/html; charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit */
>
>
> //--PHP-alt-
>
> echo $random_hash;
>
> //--PHP-mixed-
>
>
> echo $random_hash;
>
> /* Content-Type: application/zip; name="attachment.zip"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment */
>
> echo $attachment;
> //--PHP-mixed-
>
> echo $random_hash;
>
>
> //copy current buffer contents into $message variable and delete current
> output buffer
> $message = ob_get_clean();
> //send the email
> $mail_sent = @mail( $to, $subject, $message, $headers );
> //if the message is sent successfully print "Mail sent". Otherwise print
> "Mail failed"
> echo $mail_sent ? "Mail sent" : "Mail failed";
>
>
>
> echo "Thank you for contacting <b>888!</b><br /><br />";
> echo "You have submitted the following information:<br /><br />";
> echo "Name: $fname $lname<br />";
> echo "E-Mail Address: $email<br />";
> echo "Your comments or request: $comments<br /><br /><br />";
>
>
>
>
> echo "We have also sent you an e-mail to $email with the submitted
> information as well as our contact information for your convienience. <br
> /><br />
> Thank you for the opportunity to serve you!";
>
>
> /*This is the email message to submitter*/
> $contact="888\n 888\n 888";
> $from_d="$email";
> $to_d="$email";
> $subject_d='Thank you from 888';
> $msg_d="Thank you $fname for your submission, find our contact information
> listed for your convenience.\n\n"
> ."$contact\n\n"
> . "You have submitted the following information\n\n"
> . "Name: $fname $lname \n"
> . "E-Mail Address: $email\n"
> . "Comments: $comments\n"
> ;
> mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);
>
>
> /*this is to form owner, */
> $from="$email";
> $to="myemail";
> $subject="Submission from 888";
> $msg= "This is a submission from 888com. \n\n"
> . "Clients Name: $fname . $lname \n"
> . "Email Address: $email\n"
> . "Comments: $comments\n"
> ;
>
>
> mail($to, $subject, $msg, 'From:' .$from);
>
> ?>
>
>
>
> __________ Information from ESET Smart Security, version of virus signature database 5228 (20100625) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Your script can't find the attachment.zip file. As you're using a
relative path to it, it should be in the same directory as your php
script, or somewhere directly in the path environment variable.

Also, make sure that the file has read properties set to allow Apache to
read it.

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Bastien Koert on
On Fri, Jun 25, 2010 at 9:59 AM, Ashley Sheridan
<ash(a)ashleysheridan.co.uk> wrote:
> On Fri, 2010-06-25 at 09:51 -0400, Gary wrote:
>
>> I am trying to have an attachment to an email from a form.  Email is working
>> fine, am unable to get attachment. The attachment will be a word.doc.
>>
>> I am getting error message
>>
>> Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
>> failed to open stream: No such file or directory in
>> /home/oneonel1/public_html/emailreminderresult.inc.php on line 24
>> Mail failed
>>
>> Line 24 reads:
>>
>> $attachment =
>> chunk_split(base64_encode(file_get_contents('attachment.zip')));
>>
>> here is the all of the code that I have removed the email addresses & such.
>>
>> Can someone point me in the right direction?
>>
>> Thank you
>>
>> Gary
>>
>> <?php
>> $fname=stripslashes($_POST['fname']);
>> $lname=stripslashes($_POST['lname']);
>> $email=stripslashes($_POST['email']);
>> $comments=stripslashes($_POST['comments']);
>> $ip= $_SERVER['REMOTE_ADDR'];
>> $attachment = $_POST['attachment'];
>>
>> $attachment = $_FILES['attachment']['name'];
>> $attachment_type = $_FILES['attachment']['type'];
>> $attachment_size = $_FILES['attachment']['size'];
>>
>> //create a boundary string. It must be unique
>> //so we use the MD5 algorithm to generate a random hash
>> $random_hash = md5(date('r', time()));
>> //define the headers we want passed. Note that they are separated with \r\n
>> $headers = "From: myemail\r\nReply-To: myemail.com";
>> //add boundary string and mime type specification
>> $headers .= "\r\nContent-Type: multipart/mixed;
>> boundary=\"PHP-mixed-".$random_hash."\"";
>> //read the atachment file contents into a string,
>> //encode it with MIME base64,
>> //and split it into smaller chunks
>> $attachment =
>> chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 24
>> //define the body of the message.
>> ob_start();
>>
>> //Turn on output buffering
>>
>> //--PHP-mixed-
>>  echo $random_hash;
>> //Content-Type: multipart/alternative; boundary="PHP-alt-
>>  echo $random_hash;
>>
>> //--PHP-alt-
>>  echo $random_hash;
>>
>> /* Content-Type: text/plain; charset="iso-8859-1"
>> Content-Transfer-Encoding: 7bit */
>>
>>
>>
>> //--PHP-alt-
>>  echo $random_hash;
>> /* Content-Type: text/html; charset="iso-8859-1"
>> Content-Transfer-Encoding: 7bit */
>>
>>
>> //--PHP-alt-
>>
>>  echo $random_hash;
>>
>> //--PHP-mixed-
>>
>>
>> echo $random_hash;
>>
>> /* Content-Type: application/zip; name="attachment.zip"
>> Content-Transfer-Encoding: base64
>> Content-Disposition: attachment  */
>>
>>  echo $attachment;
>> //--PHP-mixed-
>>
>>  echo $random_hash;
>>
>>
>> //copy current buffer contents into $message variable and delete current
>> output buffer
>> $message = ob_get_clean();
>> //send the email
>> $mail_sent = @mail( $to, $subject, $message, $headers );
>> //if the message is sent successfully print "Mail sent". Otherwise print
>> "Mail failed"
>> echo $mail_sent ? "Mail sent" : "Mail failed";
>>
>>
>>
>> echo "Thank you for contacting <b>888!</b><br /><br />";
>> echo "You have submitted the following information:<br /><br />";
>> echo "Name: $fname  $lname<br />";
>> echo "E-Mail Address: $email<br />";
>> echo "Your comments or request: $comments<br /><br /><br />";
>>
>>
>>
>>
>>  echo "We have also sent you an e-mail to $email with the submitted
>> information as well as our contact information for your convienience. <br
>> /><br />
>>  Thank you for the opportunity to serve you!";
>>
>>
>> /*This is the email message to submitter*/
>> $contact="888\n 888\n 888";
>> $from_d="$email";
>> $to_d="$email";
>> $subject_d='Thank you from 888';
>> $msg_d="Thank you $fname for your submission, find our contact information
>> listed for your convenience.\n\n"
>> ."$contact\n\n"
>> . "You have submitted the following information\n\n"
>> . "Name:  $fname  $lname \n"
>> . "E-Mail Address: $email\n"
>> . "Comments: $comments\n"
>> ;
>> mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);
>>
>>
>> /*this is to form owner, */
>> $from="$email";
>> $to="myemail";
>> $subject="Submission from 888";
>> $msg= "This is a submission from 888com. \n\n"
>> . "Clients Name: $fname . $lname \n"
>> . "Email Address: $email\n"
>> . "Comments: $comments\n"
>> ;
>>
>>
>> mail($to, $subject, $msg, 'From:' .$from);
>>
>> ?>
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus signature database 5228 (20100625) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
> Your script can't find the attachment.zip file. As you're using a
> relative path to it, it should be in the same directory as your php
> script, or somewhere directly in the path environment variable.
>
> Also, make sure that the file has read properties set to allow Apache to
> read it.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

Consider using something like phpmailer to handle the emails. Makes
attaching things really simple.

http://phpmailer.worxware.com/

--

Bastien

Cat, the other other white meat
From: "Gary" on

"Ashley Sheridan" <ash(a)ashleysheridan.co.uk> wrote in message
news:1277474393.2787.82.camel(a)localhost...
> On Fri, 2010-06-25 at 09:51 -0400, Gary wrote:
>
>> I am trying to have an attachment to an email from a form. Email is
>> working
>> fine, am unable to get attachment. The attachment will be a word.doc.
>>
>> I am getting error message
>>
>> Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
>> failed to open stream: No such file or directory in
>> /home/oneonel1/public_html/emailreminderresult.inc.php on line 24
>> Mail failed
>>
>> Line 24 reads:
>>
>> $attachment =
>> chunk_split(base64_encode(file_get_contents('attachment.zip')));
>>
>> here is the all of the code that I have removed the email addresses &
>> such.
>>
>> Can someone point me in the right direction?
>>
>> Thank you
>>
>> Gary
>>
>> <?php
>> $fname=stripslashes($_POST['fname']);
>> $lname=stripslashes($_POST['lname']);
>> $email=stripslashes($_POST['email']);
>> $comments=stripslashes($_POST['comments']);
>> $ip= $_SERVER['REMOTE_ADDR'];
>> $attachment = $_POST['attachment'];
>>
>> $attachment = $_FILES['attachment']['name'];
>> $attachment_type = $_FILES['attachment']['type'];
>> $attachment_size = $_FILES['attachment']['size'];
>>
>> //create a boundary string. It must be unique
>> //so we use the MD5 algorithm to generate a random hash
>> $random_hash = md5(date('r', time()));
>> //define the headers we want passed. Note that they are separated with
>> \r\n
>> $headers = "From: myemail\r\nReply-To: myemail.com";
>> //add boundary string and mime type specification
>> $headers .= "\r\nContent-Type: multipart/mixed;
>> boundary=\"PHP-mixed-".$random_hash."\"";
>> //read the atachment file contents into a string,
>> //encode it with MIME base64,
>> //and split it into smaller chunks
>> $attachment =
>> chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line
>> 24
>> //define the body of the message.
>> ob_start();
>>
>> //Turn on output buffering
>>
>> //--PHP-mixed-
>> echo $random_hash;
>> //Content-Type: multipart/alternative; boundary="PHP-alt-
>> echo $random_hash;
>>
>> //--PHP-alt-
>> echo $random_hash;
>>
>> /* Content-Type: text/plain; charset="iso-8859-1"
>> Content-Transfer-Encoding: 7bit */
>>
>>
>>
>> //--PHP-alt-
>> echo $random_hash;
>> /* Content-Type: text/html; charset="iso-8859-1"
>> Content-Transfer-Encoding: 7bit */
>>
>>
>> //--PHP-alt-
>>
>> echo $random_hash;
>>
>> //--PHP-mixed-
>>
>>
>> echo $random_hash;
>>
>> /* Content-Type: application/zip; name="attachment.zip"
>> Content-Transfer-Encoding: base64
>> Content-Disposition: attachment */
>>
>> echo $attachment;
>> //--PHP-mixed-
>>
>> echo $random_hash;
>>
>>
>> //copy current buffer contents into $message variable and delete current
>> output buffer
>> $message = ob_get_clean();
>> //send the email
>> $mail_sent = @mail( $to, $subject, $message, $headers );
>> //if the message is sent successfully print "Mail sent". Otherwise print
>> "Mail failed"
>> echo $mail_sent ? "Mail sent" : "Mail failed";
>>
>>
>>
>> echo "Thank you for contacting <b>888!</b><br /><br />";
>> echo "You have submitted the following information:<br /><br />";
>> echo "Name: $fname $lname<br />";
>> echo "E-Mail Address: $email<br />";
>> echo "Your comments or request: $comments<br /><br /><br />";
>>
>>
>>
>>
>> echo "We have also sent you an e-mail to $email with the submitted
>> information as well as our contact information for your convienience. <br
>> /><br />
>> Thank you for the opportunity to serve you!";
>>
>>
>> /*This is the email message to submitter*/
>> $contact="888\n 888\n 888";
>> $from_d="$email";
>> $to_d="$email";
>> $subject_d='Thank you from 888';
>> $msg_d="Thank you $fname for your submission, find our contact
>> information
>> listed for your convenience.\n\n"
>> ."$contact\n\n"
>> . "You have submitted the following information\n\n"
>> . "Name: $fname $lname \n"
>> . "E-Mail Address: $email\n"
>> . "Comments: $comments\n"
>> ;
>> mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);
>>
>>
>> /*this is to form owner, */
>> $from="$email";
>> $to="myemail";
>> $subject="Submission from 888";
>> $msg= "This is a submission from 888com. \n\n"
>> . "Clients Name: $fname . $lname \n"
>> . "Email Address: $email\n"
>> . "Comments: $comments\n"
>> ;
>>
>>
>> mail($to, $subject, $msg, 'From:' .$from);
>>
>> ?>
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus
>> signature database 5228 (20100625) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
> Your script can't find the attachment.zip file. As you're using a
> relative path to it, it should be in the same directory as your php
> script, or somewhere directly in the path environment variable.
>
> Also, make sure that the file has read properties set to allow Apache to
> read it.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
Ashley

Thank you for your response and I'm sorry for the delay. I'm not sure I
understand your answer. I tried changing the 'attahcment.zip' to
$attachment, even creating a temp folder with reference to the path, however
it does not seem to work.

Perhaps you could explain a little further?

Again, thank you for your response.

Gary



__________ Information from ESET Smart Security, version of virus signature database 5230 (20100625) __________

The message was checked by ESET Smart Security.

http://www.eset.com