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.
|