· 8 years ago · Mar 18, 2018, 10:24 PM
1<form method="post" action="phpmailer.php">
2 <input type="text" placeholder="Nome" name="nome">
3 <input type="email" placeholder="E-mail" name="email">
4
5 <button type="submit">Enviar</button>
6</form>
7
8<?php
9 require 'phpmailer/PHPMailerAutoload.php';
10
11 $mail = new PHPMailer;
12
13 $mail->isSMTP();
14 $mail->Host = 'smtp.gmail.com';
15 $mail->SMTPAuth = true;
16 $mail->Username = '*********@gmail.com';
17 $mail->Password = '*********';
18 $mail->SMTPSecure = 'ssl'; // tls
19 $mail->Port = 465; // 587
20
21 $mail->setFrom('exemplo@exemplo.com', 'Exemplo');
22 $mail->addAddress('exemplo@exemplo.com');
23 $mail->addReplyTo('exemplo@exemplo.com', 'Exemplo');
24
25 $mail->isHTML(true);
26
27 $mail->Subject = 'Assunto';
28 $mail->Body = 'Mensagem';
29 $mail->AltBody = 'Mensagem';
30
31 if(!$mail->send()){
32 echo 'Message could not be sent.';
33 echo 'Mailer Error: '.$mail->ErrorInfo;
34 } else{
35 echo 'Message has been sent';
36 }
37?>
38
39smtp error: failed to connect to server: network is unreachable (101)