· 9 years ago · Jul 08, 2017, 07:28 PM
1<?php
2
3 session_start();
4 require_once 'phpmailer/PHPMailerAutoload.php';
5
6 $errors=[];
7
8
9 if (isset($_POST['name'], $_POST['email'], $_POST['message'])) {
10
11 $fields = [
12 'name'=> $_POST['name'],
13 'email'=>$_POST['email'],
14 'message'=>$_POST['message']
15 ];
16
17 if(empty($errors)){
18
19 $m = new PHPMailer();
20 $m->isSMTP();
21 $m->SMTPDebug =2;
22 $m->SMTPAuth = true;
23 $m->isHTML(true);
24
25 $m->Host = 'smtp.gmail.com';
26 $m->Username = '*********@gmail.com'; // its correct
27 $m->Password ='*******'; //its correct!
28 $m->SMTPSecure = 'ssl'; // I puts tls and don't works
29 $m->Port = 465; // I change this also
30 $mail->Debugoutput = 'html';
31
32
33 $m->Subject = 'Asunto';
34 $m->Body = 'De: ' .$fields['name'] . ' ('.$fields['email'].')<p>'.$fields['message'].'</p>';
35
36 $m->FromName = 'SoyCanatlan';
37
38 $m->addAddress('*******@gmail.com','******');// Here is my name and my email
39
40 if($m->send()) {
41 echo "Error!: ".$m->errors;
42 }else {
43 header('Location: thanks.php');//There is no error, send me this .php
44 }
45 }