PHP Tutorial: Email File Attachments [part 02]
Posted: Mon Mar 12, 2012 7:32 pm
I'd like to start just by saying thanks for making the tutorials, they're so easy to follow.
Whilst attempting this tutorial, I've got to the end and I have the following error message on the mail.inc.php script :
The code I've wrote is as follows;
Whilst attempting this tutorial, I've got to the end and I have the following error message on the mail.inc.php script :
Parse error: syntax error, unexpected '(', expecting ')' in C:\xampp\htdocs\core\inc\mail.inc.php on line 11
The code I've wrote is as follows;
<?php //sends the given message to the emil with fiel attatchement function mail_file($to, $from, $subject, $body, $file){ $boundary = md5(rand()); $headers = array( 'MIME-VERSION: 1.0', "From {$from}", "Content-Type: multipart/mixed; boundary="($boundary)" "); // 8bit works better? $message = array( "--{$boundary}", "Content Type: text/plain: charset utf-8", "Content-Transfer-Encoding: 7bit", "", chunk_split($body), "--{$boundary}", "Content-Type: {$file['type']}; name="{$file['name']}"; ", "Content-Disposition: attachment; filename="{$file['name']}"; ", "Content-Transfer-Encoding: base64", "", chunk_split(base64_encode(file_get_contents($file['path']))), "--{$boundary}--", ); return mail($to,$subject, $message, implode("\r\n", $message), implode("\r\n", $headers)); } ?>Help would be greatly appreciated!