Email PHPMailer to Hotmail

I am not able to send an email from the form to my Hotmail email. Below are the codes:

Form with the data to be sent.

<form id="form-contato" method="post" action="email.php">
    <div>
        <div class="row">
            <div class="6u 12u(mobile)">
                <input type="text" name="name" id="nome" placeholder="Nome" />
            </div>
            <div class="6u 12u(mobile)">
                <input type="text" name="email" id="email" placeholder="Email" />
            </div>
        </div>
        <div class="row">
            <div class="12u">
                <input type="text" name="subject" id="assunto" placeholder="Assunto" />
            </div>
        </div>
        <div class="row">
            <div class="12u">
                <textarea name="message" id="mensagem" placeholder="Mensagem"></textarea>
            </div>
        </div>
        <div class="row 200%">
            <div class="12u">
                <ul class="actions">
                    <li><input type="submit" value="Enviar mensagem"/></li>
                    <li><input type="reset" value="Limpar campos" class="alt" /></li>
                </ul>
            </div>
        </div>
    </div>
</form>

Email class.php to capture the form data and send the email:

<?php 

  require_once 'PHPMailer/PHPMailerAutoload.php';

  $mail = new PHPMailer;
  $mail->SMTPDebug=1;
  $mail->isSMTP();
  $mail->CharSet = "utf8";
  $mail->Host = 'smtp.live.com';
  $mail->SMTPAuth = true;
  $mail->Username = '[email protected]';
  $mail->Password = 'minhasenha';
  $mail->SMTPSecure = 'tls';
  $mail->Port = 465; 
  $mail->FromName = "De";
  $mail->isHTML(true);
  $mail->addAddress($_POST['email'],$_POST['nome']);
  $mail->Subject = $_POST['assunto'];
  $mail->Body =$_POST['mensagem'];

  if(!$mail->Send()){       
      echo 'Erro ao enviar e-mail: '.$mail->ErrorInfo;
  }else{
      echo 'E-mail enviado';
  }

Error returned:

insert the description of the image here

Author: Raphael Prado de Oliveira, 2017-02-10

1 answers

The port used by Hotmail is Port 587, so:

$mail->Port = 587;

What can be tried besides changing the port, is to change SMTPSecure, since Hotmail uses StartTLS , so:

$mail->SMTPSecure = 'ssl';

Check in the Hotmail settings if it allows an external SMTP client to make the connection.

 2
Author: Rodrigo Jarouche, 2017-02-10 18:03:39