Send form to Email

0
<form method="post" action="phpmailer.php">
    <input type="text" placeholder="Nome" name="nome">
    <input type="email" placeholder="E-mail" name="email">

    <button type="submit">Enviar</button>
</form>

PHPMailer

<?php
    require 'phpmailer/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = '*********@gmail.com';
    $mail->Password = '*********';
    $mail->SMTPSecure = 'ssl';                   // tls
    $mail->Port = 465;                           // 587

    $mail->setFrom('[email protected]', 'Exemplo');
    $mail->addAddress('[email protected]');
    $mail->addReplyTo('[email protected]', 'Exemplo');

    $mail->isHTML(true);

    $mail->Subject = 'Assunto';
    $mail->Body    = 'Mensagem';
    $mail->AltBody = 'Mensagem';

    if(!$mail->send()){
        echo 'Message could not be sent.';
        echo 'Mailer Error: '.$mail->ErrorInfo;
    } else{
        echo 'Message has been sent';
    }
?>

Error

smtp error: failed to connect to server: network is unreachable (101)

The most recent version of the library is being used.

GMail is already configured for less secure applications.

    
asked by anonymous 18.03.2018 / 23:09

0 answers