Zaloguj | Zarejestruj | FAQ
Anonymous

Erro no envio de email - FORMULÁRIO HTML -

+ Odpowiedz

Posty: 3 Strona 1 z 1


Erro no envio de email - FORMULÁRIO HTML -

przez marcosmaranzana » Pn wrz 15, 2014 11:12 pm

Boa noite pessoal,

Não estou conseguindo fazer com que este formulário envie o email, segue o php e o HTML

-----------------------------

PHP:

<?php
/*
* Contact Form Class
*/


header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

$admin_email = 'designemdobro@gmail.com'; // Your Email
$message_min_length = 5; // Min Message Length


class Contact_Form{
function __construct($details, $email_admin, $message_min_length){

$this->name = stripslashes($details['name']);
$this->email = trim($details['email']);
$this->subject = 'www.designemdobro.com.br'; // Subject
$this->message = stripslashes($details['message']);

$this->email_admin = $email_admin;
$this->message_min_length = $message_min_length;

$this->response_status = 1;
$this->response_html = '';
}


private function validateEmail(){
$regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';

if($this->email == '') {
return false;
} else {
$string = preg_replace($regex, '', $this->email);
}

return empty($string) ? true : false;
}


private function validateFields(){
// Check name
if(!$this->name)
{
$this->response_html .= '<p>Por favor coloque o seu nome</p>';
$this->response_status = 0;
}

// Check email
if(!$this->email)
{
$this->response_html .= '<p>Por favor coloque algum e-mail</p>';
$this->response_status = 0;
}

// Check valid email
if($this->email && !$this->validateEmail())
{
$this->response_html .= '<p>Por favor coloque um e-mail válido</p>';
$this->response_status = 0;
}

// Check message length
if(!$this->message || strlen($this->message) < $this->message_min_length)
{
$this->response_html .= '<p>Por favor coloque alguma mensagem. Ela deve ter pelo menos '.$this->message_min_length.' caracteres</p>';
$this->response_status = 0;
}
}


private function sendEmail(){
$mail = mail($this->email_admin, $this->subject, $this->message,
"From: ".$this->name." <".$this->email.">\r\n"
."Reply-To: ".$this->email."\r\n"
."X-Mailer: PHP/" . phpversion());

if($mail)
{
$this->response_status = 1;
$this->response_html = '<p>Obrigado por entrar em contato!</p>';
}
}


function sendRequest(){
$this->validateFields();
if($this->response_status)
{
$this->sendEmail();
}

$response = array();
$response['status'] = $this->response_status;
$response['html'] = $this->response_html;

echo json_encode($response);
}
}


$contact_form = new Contact_Form($_POST, $admin_email, $message_min_length);
$contact_form->sendRequest();

?>

-------------------------------------

HTML

<!-- Contact Form -->
<div class="row">
<div class="span9">

<form id="contact-form" class="contact-form" action="http://www.designemd...p/contact.php">
<p class="contact-name">
<input id="contact_name" type="text" placeholder="Nome Completo" value="" name="name" />
</p>
<p class="contact-email">
<input id="contact_email" type="text" placeholder="Email" value="" name="email" />
</p>
<p class="contact-message">
<textarea id="contact_message" placeholder="Mensagem" name="message" rows="15" cols="40"></textarea>
</p>
<p class="contact-submit">
<a id="contact-submit" class="submit" href="#">Enviar</a>
</p>

<div id="response">

</div>
</form>


Obrigado!
Avatar użytkownika

marcosmaranzana

  • Posty: 5
  • Dołączył(a): Cz lut 13, 2014 5:11 pm

Re: Erro no envio de email - FORMULÁRIO HTML -

przez nanoverso » Wt wrz 16, 2014 12:51 am

Existe outra forma de envio de e-mail, usando o pacote PEAR, que retorna o tipo de erro que está ocorrendo, conforme o exemplo em:
http://email.about.com/od/emailprogramm ... cation.htm
Avatar użytkownika

nanoverso

  • Posty: 253
  • Dołączył(a): So maja 10, 2014 12:08 am
  • Lokalizacja: Brazil
--
Free VST Plugins Download.

Re: Erro no envio de email - FORMULÁRIO HTML -

przez marcosmaranzana » Wt wrz 23, 2014 5:57 pm

Obrigado pela resposta! Só que não entendi rs
Avatar użytkownika

marcosmaranzana

  • Posty: 5
  • Dołączył(a): Cz lut 13, 2014 5:11 pm


+ Odpowiedz

Strona 1 z 1