Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Email settings
- */
- // admin email
- $adminEmail = 'contato@locusmap.com.br';
- // email will arrive from
- $fromEmail = 'formulario@locusmap.com';
- // message subject
- $subject = 'Mensagem do site';
- // message intro
- $message = "Mensagem do formulário";
- /*
- * Validation settings
- */
- // required
- $required = array('name','email','message','captcha');
- // valid email
- $validEmail = array('email');
- // Do validation
- $res = array('result'=>true,'errors'=>array());
- if(!empty($_POST)){
- foreach ($_POST as $key => $value) {
- if(in_array($key, $required)){ // check if required
- if(trim($value) == ''){ // check if empty
- $res['result'] = false;
- if(!isset($res['errors'][$key])) // don't set more than one error
- $res['errors'][$key] = 'required';
- }
- }
- if(in_array($key, $validEmail)){ // check if required
- $pattern = '/^[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}$/';
- if(preg_match($pattern, $value) === 0){ // check if empty
- $res['result'] = false;
- if(!isset($res['errors'][$key])) // don't set more than one error
- $res['errors'][$key] = 'email';
- }
- }
- }
- if($res['result'] === true){ //validation passed
- // message content
- require 'PHPMailerAutoload.php';
- $mail = new PHPMailer;
- //$mail->SMTPDebug = 3; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.umbler.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'contato@locusmap.com.br'; // SMTP username
- $mail->Password = 'geografiauerj16'; // SMTP password
- $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587; // TCP port to connect to
- $mail->setFrom('formulario@locusmap.com.br', $_POST['name']);
- $mail->addAddress('contato@locusmap.com.br'); // Add a recipient
- $mail->addAddress('ellen@example.com'); // Name is optional
- $mail->addReplyTo($_POST['email']);
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Email enviado pelo site';
- $mail->Body = $_POST['message'];
- if(!$mail->send()) {
- echo 'A mensagem voltou.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- } else {
- echo 'A mensagem foi enviada!';
- }
- }
- }
- echo json_encode($res);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement