0
Hello, I’m using the following code:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Enviar e-mail com anexo</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="?acao=enviar" enctype="multipart/form-data">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td align="right">Nome:</td>
<td><input type="text" name="nome" id="nome" /></td>
</tr>
<tr>
<td align="right">Assunto:</td>
<td><input type="text" name="assunto" id="assunto" /></td>
</tr>
<tr>
<td align="right">Mensagem:</td>
<td><textarea name="mensagem" id="mensagem" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td align="right">Anexo:</td>
<td><input type="file" id="arquivo" name="arquivo" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Enviar" /></td>
</tr>
</table>
</form>
<?php
if ($_POST['acao'] == 'enviar'){
$nome = $_POST['nome'];
$assunto = $_POST['assunto'];
$mensagem = $_POST['mensagem'];
$arquivo = $_FILES["arquivo"];
$corpoMSG = "<strong>Nome:</strong> $nome<br> <strong>Mensagem:</strong> $mensagem";
// chamada da classe
require_once('class.phpmailer.php');
// instanciando a classe
$mail = new PHPMailer();
// email do remetente
$mail->SetFrom('[email protected]', 'remetente');
// email do destinatario
$address = "[email protected]";
$mail->AddAddress($address, "destinatario");
// assunto da mensagem
$mail->Subject = $assunto;
// corpo da mensagem
$mail->MsgHTML($corpoMSG);
// anexar arquivo
$mail->AddAttachment($arquivo['tmp_name'], $arquivo['name'] );
if(!$mail->Send()) {
echo "Erro: " . $mail->ErrorInfo;
} else {
echo "Mensagem enviada com sucesso!";
}
}
?>
</body>
</html>
And I’m afraid the following mistake:
( ! ) Notice: Undefined index: ? acao in C: wamp www EMAILL email.php on line 33 Call Stack
Time Memory Function Location
1 0.0050 390248 {main}( ) ... email.php:0
I really don’t understand why, I already gave a study in the code but I can not understand the error. Someone help me, please!
Good morning! I tried to make the change but got no results, it keeps returning the same error messages.
– Vinícius Augusto Gimenes
Only one, no <form id="Form1" name="Form1" method="post" action="? acao=enviar" enctype="Multipart/form-data"
– Vinícius Augusto Gimenes
This piece I posted is all my code.
– Vinícius Augusto Gimenes
The same mistake :/
– Vinícius Augusto Gimenes
Keeps returning the same error: Notice: Undefined index: acao in C: wamp www EMAILL attachment.php on line 33
– Vinícius Augusto Gimenes
All code in php?
– Vinícius Augusto Gimenes
the error does not persist
– Vinícius Augusto Gimenes
Can you recommend some code that has the same function? I really need it for a school project.
– Vinícius Augusto Gimenes
Yes, exactly
– Vinícius Augusto Gimenes
Excuse me, the fault is mine! I should have realized this mistake just by hitting the eye. I deleted the comments because it lists a long discussion that no longer makes sense.
– Augusto Vasques