Our support table can now have tickets inserted that have been sent via email, however, as one last
measure we??™re going to save the email as a file attachment just in case we need to refer to it for whatever
reason.
Saving the fetched mail to file
As we loop through the support mail messages in listing 9.11 we have all the information we need in the
$message variable to write out to a file. Listing 9.13 shows how we??™ll fulfil the third requirement by storing it
as the original email.
Listing 9.13: Writing the message out to a file
$messageString = '';
foreach ($message->getHeaders() as $name => $value) { A
$messageString .= $name . ': ' . $value . "\n";
}
$messageString .= "\n" . $message->getContent(); B
file_put_contents(getcwd() . '/support/' . $id . '/email.txt', C
$messageString
);
A Loop over the headers and append to $messageString
B Append the message content to $messageString
C Store in file in a directory named with the support ticket id
The next point is a security one; the email content could just as easily contain malicious code as any form
submission could so before we insert it into the database we we will need to add some filtering.
Filtering the email content
Just to wrap up properly in listing 9.14 we??™ll bring together all the code we??™ve done so far and add in some
basic data filtering using Zend_Filter.
Pages:
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273