Doubt to Link form in PHP to send by email

Asked

Viewed 221 times

-1

I have a small problem at the time of connecting the contact form to be sent by email, it is not sending by email and I could not understand the reason for this, follows below the html code with the name contact.html

 <form action="sendemail.php" id="main-contact-form" name="contact-form" method="post"  >
                <div class="row  wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
                  <div class="col-sm-12">
                    <div class="form-group">
                      <input type="text" name="Nome" class="form-control" placeholder="Nome" required="required">
                       <p class="help-block">Obrigatorio</p>
                    </div>
                  </div>
                  <div class="col-sm-12">
                    <div class="form-group">
                      <input type="email" name="Email" class="form-control" placeholder="Email" required="required">
                      <p class="help-block">Obrigatorio</p>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <input type="text" name="Instituição" class="form-control" placeholder="Instituição" >
                </div>
                <div class="form-group">
                  <textarea name="message" id="message" class="form-control" rows="4" placeholder="Escreve sua menssagem" required="required"></textarea>
                </div>                        
                <div class="form-group">
                  <button type="submit" class="btn-submit">Enviar</button>
                </div>
              </form>

Below is the php code with the name sendemail.php

<?php
$name       = @trim(stripslashes($_POST['Nome'])); 
$from       = @trim(stripslashes($_POST['Email'])); 
$subject    = @trim(stripslashes($_POST['Instituicao'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to   		= '[email protected]';//replace with your email




$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

?>

I am well Noob in php per hour, so I’m having this problem, the site is already on the server and I am unable to find the error.

  • HI Gabriel, where is your application hosted? Depending on where, you should use some additional parameters in the mail function.

2 answers

0

Gabriel, corrects the field name Instituição for Instituicao (unfettered).

The function mail() PHP is no longer recommended for sending emails since several reasons prevent the email from reaching the recipient, even a simple blocking of the server where the site is hosted or even the recipient’s SPAM checks.

Send using SMTP server and appropriate class for this.

I recommend the phpmailer, is famous and very simple to implement see a simple tutorial:

http://wiki.locaweb.com/pt-br/Enviar_e-mails_pelo_PHP_usando_o_PHPMailer

  • Other link on the subject: http://blog.patriciodossantos.net/2012/05/enviando-e-mail-com-o-phpmailer/

  • It didn’t work, I followed the tutorial correctly and it doesn’t work the same way. Besides that this phpmailer is for me to send email to several people, I would just like to send me the part of the form for me to know the person who contacted.

  • @Gabrielsilva, you checked the SMTP settings?

0

As mentioned above, I also recommend using the email sending class Phpmailler. I’ve been using it for a long time and I’ve never had a problem with it, is simple to use and if your email is in default it will not enter as spam in the inboxes of the mail servers (Gmail, Hotmail, etc), because it has a whole process of authentication.

Tip: Do not use variable or vector naming with special characters, you will have problems with file coding in the future.

http://www.revistaphp.com.br/artigo.php?id=78

Browser other questions tagged

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