Jump to content
Fórum Script Brasil
  • 0

Envio por e-mail de um formulário


latsp

Question

Caros, baixei um template da net, tenho um html com formulário que depois de preenchido envia o conteúdo por e-mail usando dois arquivos .php. Segui as orientações do desenvolvedor, mas o formulário não envia nada. Se alguém puder me dar uma luz, ficarei muito grato. Abaixo os dois códigos PHP. (mail.php e functions.php)

mail.php

<?php
include 'functions.php';
if (!empty($_POST)){
$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);
//your email adress
$emailTo ="yourmail@yoursite.com"; //"yourmail@yoursite.com";
//from email adress
$emailFrom ="contact@yoursite.com"; //"contact@yoursite.com";
//email subject
$emailSubject = "Mail from Porta";
$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if($name == "")
$data['success'] = false;
if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;
if($comment == "")
$data['success'] = false;
if($data['success'] == true){
$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);
$data['success'] = true;
echo json_encode($data);
}
}
functions.php
<?php
// Strips nasty tags from code..
function cleanEvilTags($data) {
$data = preg_replace("/javascript/i", "j&#097;v&#097;script",$data);
$data = preg_replace("/alert/i", "&#097;lert",$data);
$data = preg_replace("/about:/i", "&#097;bout:",$data);
$data = preg_replace("/onmouseover/i", "&#111;nmouseover",$data);
$data = preg_replace("/onclick/i", "&#111;nclick",$data);
$data = preg_replace("/onload/i", "&#111;nload",$data);
$data = preg_replace("/onsubmit/i", "&#111;nsubmit",$data);
$data = preg_replace("/<body/i", "&lt;body",$data);
$data = preg_replace("/<html/i", "&lt;html",$data);
$data = preg_replace("/document\./i", "&#100;ocument.",$data);
$data = preg_replace("/<script/i", "&lt;&#115;cript",$data);
return strip_tags(trim($data));
}
// Cleans output data..
function cleanData($data) {
$data = str_replace(' & ', ' &amp; ', $data);
return (get_magic_quotes_gpc() ? stripslashes($data) : $data);
}
function multiDimensionalArrayMap($func,$arr) {
$newArr = array();
if (!empty($arr)) {
foreach($arr AS $key => $value) {
$newArr[$key] = (is_array($value) ? multiDimensionalArrayMap($func,$value) : $func($value));
}
}
return $newArr;
}

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      652k
×
×
  • Create New...