0

Sending emails with php using mail

I'm trying to send email through php and I'm using email. I'm using locaweb's email and I'm creating everything on locaweb.

my index.php

<?php
$msg=0;
@$msg= $_REQUEST['msg'];
?>



<!DOCTYPE html>
<html lang="pt">
<head>

    <!-- meta tags requiridas -->
    <meta charset="utf-8">

    <!-- Titulo --> 
    <title>Envio de Email</title>

    <!-- favicon -->
    <link rel="shortcut icon" href="img/favicon.ico"/>

    <!-- google fonts -->
    <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i" rel="stylesheet">

    <!-- font-awesome -->
    <link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">

    <!-- bootstrap css -->
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">

    <!-- style CSS -->
    <link rel="stylesheet" href="css/style.css">

</head>
<body>  
    <?php if($msg==enviado): ?>
        <h1>Mensagem enviada, agradecemos o seu contato!</h1>
    <?php else: ?>

    <form action="email.php" method="post" class="contactForm">




                              <div class="form-group">
                                <label for="nome">Nome:</label>
                                <input type="text" class="form-control" id="nome" name="nome" required/>
                            <!--        <div class="validation"></div> -->
                              </div>
                              <div class="form-group">
                                <label for="email">Email</label>
                                    <input type="text" class="form-control" id="email" name="email" required />
                            <!--    <div class="validation"></div> -->
                              </div>
                              <div class="form-group">
                                <label for="assunto">Assunto</label>
                                <input type="text" class="form-control" id="assunto" name="assunto" required/>
                            <!--    <div class="validation"></div> -->
                              </div>
                              <div class="form-group">
                                <label for="mensagem">Mensagem</label>
                                <textarea class="form-control" name="mensagem" id="mensagem" rows="5" required placeholder="Escreva alguma mensagem"></textarea>
                            <!--    <div class="validation"></div> -->
                              </div>

                               <input type="submit" name="btn_enviar"  value="Enviar"/>
    </form>
    <?php endif; ?>

                            <script src="js/jquery.js"></script>

    <!-- boostrap js -->
    <script src="js/bootstrap/bootstrap.min.js"></script>

    <!-- custom js -->
    <script src="js/custom.js"></script>
</body>
</html>

Function that sends email and its information.

email.php

<?php


$para = "";

$assunto = "Contato pelo site";
$nome = $_REQUEST['nome'];
$email = $_REQUEST['email'];
$msg = $_REQUEST['assunto'];
$mensagem = $_REQUEST['mensagem'];

    $corpo = "<strong> Mensagem de contato</strong><br><br>";
    $corpo .= "<br><strong> Nome: </strong> $nome";
    $corpo .= "<br><strong> Email: </strong> $email";
    $corpo .= "<br><strong> Titulo: </strong> $assunto";
    $corpo .= "<br><strong> Mensagem: </strong> $mensagem";


    $header = "From : $email Reply-to: $email";
    $header .= "Content-Type: text/html; charset= utf-8";


mail($para, $assunto, $corpo, $header);

header("location:index.php?msg=enviado");



?>

After I fill in the information I am seeing the message sent successfully, but the email is not arriving.

I am trying to send emails using php mail, but it is not working.

Could someone help me?

Lucas Santos
  • 139
  • 1
  • 2
  • 7
  • check the "Related" section on the right side – ArtOsi Jul 26 '17 at 14:42
  • Check out the [PHP manual for mail()](http://php.net/manual/en/function.mail.php) and see how they are creating the headers (line breaks matters). Try the examples. It could also be that the receiving mail server blocks the emails, if the server your using isn't properly set up to be allowed to send emails from the senders hostname. – M. Eriksson Jul 26 '17 at 14:46
  • Thanks a lot for the help, I got to do with phpmailer. @MagnusEriksson – Lucas Santos Jul 27 '17 at 03:01

0 Answers0