Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help With Forms and Attachments
Old 09-25-2009, 12:19 PM Help With Forms and Attachments
Junior Talker

Posts: 1
Trades: 0
Hello,

I hope you guys can help, I am doing a project for work, I am trying to submit a form with an attachment, where the attachment will be emailed to the receiver. I would like the email to be in html also. The code I have so far is

Code:
<?php
            $to = "x@X-Company.com";
         $subject = "X-Company Customer Complaint/Parts Issue\r\n // " . $_POST['shipcompany'] . " // PR# " . $_POST['prnum'] ;
         $hash   = array();
            $hash[] = sprintf('%s-%s=:%s',time(),md5(time()),rand(0,9));
            $hash[] = sprintf('%s-%s=:%s',time(),md5(time()),rand(10000,99999));
         $headers = "From: XXXXX <x@X-Company.com>\r\n";
         $headers .= "CC: x@email.comm, x@email.com, x@X-Company.com\r\n";            $escalation = $_POST['escalation'];
         $callback = $_POST['callback'];
         $email = $_POST['email'];
         $submitter = $_POST['submitter'];
         $prnum = $_POST['prnum'];
         $comments = $_POST['comments'];
         $type = $_POST['type'];
         $ref = $_POST['ref'];
         $ref2 = $_POST['ref2'];
         $ref3 = $_POST['ref3'];
         $ref4 = $_POST['ref4'];
         $ref5 = $_POST['ref5'];
         $part = $_POST['part'];
         $part2 = $_POST['part2'];
         $part3 = $_POST['part3'];
         $part4 = $_POST['part4'];
         $part5 = $_POST['part5'];
         $shipcompany = $_POST['shipcompany'];
         $streetaddress1 = $_POST['streetaddress1'];
         $streetaddress2 = $_POST['streetaddress2'];
         $city = $_POST['city'];
         $province = $_POST['province'];
         $postalcode = $_POST['postalcode'];
         $country= $_POST['country'];
         $handle= $_POST['handle'];
         $filedir      = 'files/';
$fileArray      = array();
$attachments   = NULL;

foreach ($fileArray AS $key => $value)
{
   $fullpath = sprintf('%s/%s',$filedir,$value);
   if (!file_exists($fullpath)) { continue; }
   
   $ext      = str_replace('.',NULL,strstr($value,'.'));
   $filetype   = get_filetype($ext);
   $filechunks   = chunk_split(base64_encode(file_get_contents($fullp  ath)));
   
$attachments .= <<<MAILATTACHMENT

--$hash[1]
Content-Type: $filetype; name="$value"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$filechunks

MAILATTACHMENT;
}
$headers = <<<MAILHEADERS
From: $from
Reply-To: $from
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="$hash[0]"
MAILHEADERS;

$message = <<<MAILBODY
This is a multi-part message in MIME format.

--$hash[0]
Content-Type: multipart/alternative; boundary="$hash[1]"

--$hash[1]
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Congrats. You have an attachment!

--$hash[1]
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<html>
<head>

<title>X-Company Customer Complaint/Parts Issue</title>
<style type="text/css">
body {
   font-family: Calibri, Verdana, Trebuchet MS;
   font-size: 13px;
}

.labels {
   color: #68469A;
   font-weight: bold;
}
</style>
</head>
<body>
<font class="labels">Escalation Contact:</font> $escalation<br />
<font class="labels">Escalation Callback Number:</font> $callback<br />
<font class="labels">Escalation E-mail Address:</font> $email<br />
<font class="labels">Submitter Name:</font> $submitter<br />
<font class="labels">PR Number:</font> $prnum<br />
<font class="labels">Comments:</font> $comments<br />
<font class="labels">Service Type:</font> $type<br />
<font class="labels">X-Company Reference:</font> $ref   <font class="labels">Part / Comcode: </font> $part <br />
<font class="labels">X-Company Reference: </font> $ref2 <font class="labels">Part / Comcode: </font> $part2 <br />
<font class="labels">X-Company Reference:</font> $ref3 <font class="labels">Part / Comcode: </font> $part3 <br />
<font class="labels">X-Company Reference:</font> $ref4 <font class="labels">Part / Comcode: </font> $part4 <br />
<font class="labels">X-Company Reference:</font> $ref5 <font class="labels">Part / Comcode: </font> $part5 <br /><br />

<font class="labels">Ship To Company:</font> $shipcompany<br />
<font class="labels">Street Address (Line 1):</font> $streetaddress1<br />
<font class="labels">Street Address (Line 2):</font> $streetaddress2<br />
<font class="labels">City:</font> $city<br />
<font class="labels">State/Province:</font> $province<br />
<font class="labels">Postal Code:</font> $postalcode<br />
<font class="labels">Country:</font> $country<br /><br />

<font class="labels">Agent Handle:</font> $handle<br /><br />

Thank you, <br /><br />
<b>$submitter</b><br />
X-Company Welcome Center<br />
<font class="labels">Phone:</font> 800-888-8888<br />
<font class="labels">E-mail:</font> cmc@X-Company.com<br />
</body>
</html>

$attachments

--$hash[0]
MAILBODY;

         


$sent = mail($to, $subject, $message, $headers);
         if($sent)
         {print "Escalation mail has been sent."; }
         else
         {print "Sadly, an error has occured. Could you please retry sending? (You will have to go back and fill the form in again!)"; }
?>

Now when the form is sent on the original form page, I only receive a plain txt version and no attachment.


What is wrong with my code???

I am new to attachments with php mail.

Thanks in advance for any help.
cgycowboy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-26-2009, 01:29 AM Re: Help With Forms and Attachments
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
There was a really good example on the php site of a sendmail funtion script, but I was unable to find it. So I am uploading a slightly customized version of that script that I often use.
Attached Files
File Type: txt sendmail.functions.php.TXT (4.4 KB, 2 views)
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-26-2009, 01:31 AM Re: Help With Forms and Attachments
prasanthmj's Avatar
Experienced Talker

Posts: 42
Name: Prasanth
Trades: 0
It will be easier if you use a library like PEAR to send emails with attachments.
The following page contains an example:
PHP email form with file attachment
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
prasanthmj is offline
Reply With Quote
View Public Profile
 
Old 09-27-2009, 08:08 AM Re: Help With Forms and Attachments
Average Talker

Posts: 23
Name: Mary North
Trades: 0
PEAR is a good library for email attachments compared to other programs.
__________________

Please login or register to view this content. Registration is FREE
marynorth21 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help With Forms and Attachments
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13656 seconds with 13 queries