Send form to E-mail

Asked

Viewed 41 times

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 latest version of the library is being used.

Gmail is already set up for less secure applications.

  • Please explain what you are trying to do with this form and this PHP code

  • I need to send the form data to a Gmail Email. In this case I am using the Phpmailer library. But I get the following error: smtp error: failed to connect to server: network is unreachable (101). - I am using the latest version of the library and have already set up Gmail for less secure applications.

  • the error may be on your hosting server, it may be blocking access to the SMTP server from a look at this reply

  • Take a look at the comments, it will give you meaning. https://github.com/PHPMailer/PHPMailer/issues/149

  • I had a headache with Gmail SMTP these days, but the client was a software for Linux and not PHP. If the problem isn’t with your hosting, you’ll probably have to use port 587 even with SSL.

  • The problem may be on the server

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.