Send Mail Php oop -
this question has answer here:
i plan create contact form. validation errors operating @ 100% when there no error when sending can not receive email , not know why. i've tried several ways can me. code 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 .= '- forgot enter name!<br />'; } if ($this->email == "") { $errors .= '- forgot enter email!<br />'; } if ($this->assunto == "") { $errors .= '- forgot enter assunto!<br />'; } if ($this->mensagem == "") { $errors .= '- forgot enter 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 />'; } } } ?>
$this->admin
null
because you're setting $admin
available inside sendmail()
function's scope.
either set $this->admin
or use $admin
in mail()
function:
$this->admin = 'your@email.com';
Comments
Post a Comment