Click here to Skip to main content
15,668,646 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi Team

I am trying to find where could i omit end of curly braces i dont seem to see clearly and im using my ide. Help fix this issue

What I have tried:

function multi_attach_mail($to, $subject, $message, $senderEmail, $senderName, $received_email_send = array()){
  // Sender info
$from = $senderName. '<.$senderEmail.>';
$headers = 'From: $from';

// Boundary
$semi_rand = md5(time());
$mime_boundary = '==Multipart_Boundary_x{$semi_rand}x';

// Headers for attachment
$headers .= '\nMIME-Version: 1.0\n' .
"Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

// Multipart boundary
$message = "–{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";

// Preparing attachment
$file_name = basename($received_email_send[$i]);
$file_size = filesize($received_email_send[$i]);
$message .= "–{$mime_boundary}\n";
$fp = @fopen($received_email_send[$i], "rb");
$data = @fread($fp, $file_size);
$data = chunk_split(base64_encode($data));
"Content-Disposition: attachment; filename=\"".$file_name."\"\n" .
"Content-Length: ".$file_size."\n" .
"Content-Type: application/octet-stream; name=\"".$file_name."\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";

$message .= "–{$mime_boundary}\n";
$returnpath = "-f" . $senderEmail;

// Send email
$mail = mail($to, $subject, $message, $headers, $returnpath);
// Return true if email sent, otherwise return false
return true;
return false;

Updated 7-Mar-23 9:35am
Richard MacCutchan 7-Mar-23 15:06pm    
If you used proper indentation in your code it should be possible to see where the problem is. Issues like this you shgould be able to fix yourself, especially inside an IDE, which will probably flag the bad items for you.

1 solution

With no idea what line the error is reported on, and unindented code being a mess to read at the best of times, it's difficult to tell exactly where you problem is.
But ... it looks like you have spurious "}" after this:
Content-Length: ".$file_size."\n" .
"Content-Type: application/octet-stream; name=\"".$file_name."\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900