-2

people. I'm fairly new to coding; I've been watching tutorials and reading about it for about two months. My motivation for learning it is to make a website for my cousin who so dearly wants one, but currently neither has the money to pay someone to do it for him, nor does he have the time or mindspace to learn it.

But, I do! So, here I am. I'm learning codes to make a website for him. I also believe it can help me on some of my projects but my real motivation is that.

I've been struggling with two aspects of e-mail forms -- One is this: [three call stack erros saying I didn't define the form names, I believe, although it seems to me that I did]

[removed some stuff]

EDIT

I'm currently using google smtp.gmail server, but to no success. I've corrected, to my knowledge, my code, but I still have no success in making the email form work. Here is the code:

<?php 
if(isset($_POST['enviar'])):
 $from=isset($_POST['nome']) ? $_POST['nome'] : '';
 $to='my_email@gmail.com';
 $subject= isset($_POST['assunto']) ? $_POST['assunto'] : '';
 $message=$_POST['mensagem'];
 $email=isset($_POST['email']) ? $_POST['email'] : '';
 if (mail($to, $subject, $message, 'from'.$email):
  $aviso= 'email enviado';
 else:
  $aviso='falha ao enviar email';
 endif;
endif;

 ?>
<div class="first">
 <form action="" method="post">

  <label for="name">Nome:</label> <br>
  <input id="name" type="text" class="inserir" name="nome" /> <br/>

  <label for="mailfrom">E-mail:</label> <br>
  <input id="mailfrom" type="text" class="inserir" name="email" />  <br />

  <label for="topic">Assunto:</label> <br>
  <input id="topic" type="text"  name="assunto" class="inserir" /> <br /></div>

  <textarea name="mensagem" id="inserirmensagem" placeholder="Digite sua mensagem..." class="inserir"></textarea><br />

  <input type="submit" class="enviar" name="enviar" value="Enviar mensagem &raquo;"></input>

  <?php if(isset($aviso)) echo $aviso;  ?>
 </form>
</div>
Paulo Soares
  • 177
  • 3
  • 18
  • 1
    Please add actual code to your question; screenshots of code are not appropriate. FYI, `` tags are self closing (ie, no ``). Also, the `form` attribute should be the ID of the `
    `. I believe this is the cause of your problem
    – Phil Jul 04 '16 at 23:41
  • Also, not to undermine your efforts to learn web development but your cousin should probably just go with a Wordpress site. You should definitely continue to learn though. – Phil Jul 04 '16 at 23:43

1 Answers1

0

I believe the issue is your incorrect use of the form attribute (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form).

As you have no <form> with IDs nome, email, etc, your inputs are not being associated with a valid form.

Simplify your inputs

<label for="nome">Nome:</label><br>
<input type="text" id="nome" name="nome" class="inserir"><br>

Your use of mail also appears incorrect. I suggest using a library like Swift Mailer and an external SMTP server such as Google. Setting up your own SMTP host is quite difficult.

Phil
  • 157,677
  • 23
  • 242
  • 245
  • Thank you. With your help, I've managed to remove the call stack errors. I've also seen some defecs on my code. I'm also >trying to< use smtp.gmail but I have no success yet. – Paulo Soares Jul 06 '16 at 06:07
  • @PauloSoares your `from` header is wrong. I **very strongly suggest** you use a mail library like Swift Mailer. – Phil Jul 06 '16 at 07:03