Re: Attachment to email from form.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 25, 2010 at 9:59 AM, Ashley Sheridan
<ash@xxxxxxxxxxxxxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux