In such cases a screenshot of the
offending page can be a great help and that is the reason why adding attachments to the support email is the
fifth requirement of our application.
We have already added a file input field to the support ticket submission form which the user will use to
browse for their screenshot file and have it uploaded on submission of the form. The process of actually
dealing with the uploaded file isn??™t something we can do justice to in this chapter but let us imagine it is
something along the lines of:
move_uploaded_file(
$_FILES[???attachment??™]['tmp_name'],
realpath(getcwd()) . '/support/' . $id . '/'
);
This moves the uploaded file, which we will call error-screenshot.jpg, to a sub-directory of /support/ using
the support ticket id as its directory name.
Now that we have the file in place we can attach it to the email with the code shown in listing 9.7
Listing 9.7: Attaching the screenshot file to the support email
$file = "/home/places/public_html/support/67/error-screenshot.jpg"; A
$fileBody = file_get_contents($file); A
$fileName = basename($file); A
$fileType = mime_content_type($file); A
$at = $mail->addAttachment($fileBody); B
$at->filename = $fileName; C
$at->type = $fileType; C
Licensed to Menshu You
Pages:
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262