Could not acess file: Array e syntax error, Unexpected '$name' (T_VARIABLE)

Asked

Viewed 104 times

2

I am using Phpmailer to send an attached email by a form, my code has no errors, but when I finish the form and press send, returns an error but that the email was sent. Code:

   $name=$_REQUEST['name'];
   $email=$_REQUEST['email'];
   $message= $_REQUEST['message'];
   $message= "--$boundary" . PHP_EOL;
   $message= "Content-Type: text/html; charset='utf-8'" . PHP_EOL;
   $message= "--$boundary" . PHP_EOL;
   $tapete=$_REQUEST['tapete'];
   $medidas=$_REQUEST['medidas'];
   $cliente=$_REQUEST['cliente'];
   $mail = new PHPMailer();
   $mail->isSMTP();
   $mail->SMTPDebug = 2;
   $mail->Debugoutput = 'html';
   $mail->Host = 'smtp.gmail.com';
   $mail->Port = 587;
   $mail->SMTPSecure = 'tls';
   $mail->SMTPAuth = true;
   $mail->Username = "[email protected]";
   $mail->Password = "123Password";
   $mail->setFrom = ('[email protected]');
   $mail->Subject   = 'Formulário FacilityCom';
   $mail->Body      = 'Tipo e marca: $tapete \nMedidas: $medidas \nCliente: $cliente\n $from';
   $mail->AddAddress= ('[email protected]');
   $mail->IsHTML(true);
   $file_to_attach = $_FILES['file'];
   $filename=$_FILES['file'];
   $mail->AddAttachment($file_to_attach, $filename);
   $mail->Send();

The mistake I get is:

Parse error: syntax error, Unexpected '$name' (T_VARIABLE) in /home/u746419992/public_html/index.php on line 42

  • $filename and $file_to_attach have the same value. That’s right?

  • @Mucap but that fields, I think you do not understand, error_reporting It’s a setup so you can see the errors. Andre’s answer says you tried to set variables, but they’re actually methods, the sign of = has been used, must follow the documentation of phpmailer, has places that are variable and has sites that are methods, it seems to me that this is the problem, without wanting to offend, it seems to me that you do not understand what are functions, classes and variables right yet. I am wrong?

  • @Mucap you did not put the error there in the question, sorry but I have explained twice. I hope you will not misunderstand me, read this link: http://answall.com/help/mcve :)

  • By the error seems that you only posted part of the code, again I ask you to read the link I sent you and follow the tips, because this difficult to help with the current information, because this error is a typo yours, but with only part of the code there is no way to find where this error, read carefully and follow the tips: http://answall.com/help/mcve - I hope you understand as a constructive criticism :)

2 answers

2


  • It seems that it is correct, note that AddAddress = should be AddAddress(...), same situation. + 1

0

Mucap, this will happen even if you use a Multiple in your input:file

If you have more than one file, the treatment will be different.

Probably, your form is like this:

<input name="file[]" type="file" />

Change to

<input name="file" type="file" />
  • No, it’s just like what you said I should do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.