Send Mail Php oop [duplicate]

This question already has an answer here:

I plan to create a contact form.
The validation errors are operating at 100% but when there is no error when sending can not receive email and do not know why.
I’ve tried several ways someone can help me.
The code is this:

CONTACT:

<?php 

require_once('../classes/db_funcoes.php');
require_once("../classes/contacto_class.php");

?> 

                <form method="post"> 
                    <p style="padding: 0 20px; margin-top: -15px;"><span style="color: red;">
                        <?php 

                        if(isset($_POST['submit'])) {
                            $sendMail = new contactos();
                            $sendMail->nome   = $_POST['nome'];
                            $sendMail->email  = $_POST['email'];
                            $sendMail->assunto  = $_POST['assunto'];
                            $sendMail->mensagem  = $_POST['mensagem'];
                            $sendMail->sendMail();
                        } ?>
                    </span></p>
                            <input name="nome" type="text" class="form-control" id="name" placeholder="ex: João" value="<?php if (isset($_POST['nome'])) { echo $_POST['nome']; } ?>"/>
                            <input name="email" type="email" class="form-control" id="email" placeholder="ex: email@sapo.pt" value="<?php if (isset($_POST['email'])) { echo $_POST['email']; } ?>" />
                            <select id="subject" name="assunto" class="form-control" >
                                <option value="na" selected="">Escolher Assunto:</option>
                                <option value="service">Problemas de serviço</option>
                                <option value="suggestions">Sugestões</option>
                                <option value="product">Produtos</option>
                            </select>
                            <textarea style="resize: none; color: #222;" name="mensagem" id="message" class="form-control" rows="9" cols="25" placeholder="Mensagem"><?php if (isset($_POST['mensagem'])) { echo $_POST['mensagem']; } ?></textarea>
                        <input type="submit" name="submit" class="btn btn-primary pull-right" id="btnContactUs" value="Enviar Mensagem">
                </form>

CONTACT_CLASS:

<?php

class contactos {

    var $nome;
    var $email;
    var $assunto;
    var $mensagem;
    var $admin;

    public function sendMail() 
    {
            $errors = "";
            $admin = "josecerejo@sapo.pt"; 

            if ($this->nome == "") {
                $errors .= '- You forgot to enter a name!<br />';
            }

                if ($this->email == "") {
                $errors .= '- You forgot to enter an email!<br />';
            }

                if ($this->assunto == "") {
                $errors .= '- You forgot to enter a assunto!<br />';
            }

                if ($this->mensagem == "") {
                $errors .= '- You forgot to enter a mensagem!<br />';
            }

            if(empty($errors)) {
            $headers = "From: ".$this->nome." <".$this->email.">";
            $send_contact=mail("$this->admin","$this->assunto","$this->mensagem","$headers");
            exit();
            } else {
                echo '<p class='message error'>';
                echo '<font color="black">' . $errors . '</font>';
                echo '</p><br />';
            }
        } 
    } 
?>


Source: oop

Leave a Reply