0

I'm trying to send an email through a contact form from PHPMAILER and sending get the following error (I'm working from Localhost).

Could not access file: SMTP Error: Could not connect to SMTP host.

This is my code

//Libs
include_once('class.phpmailer.php');
include_once('class.smtp.php');

//Receive all the parameters of the form
$para = $_POST['email'];
$asunto = $_POST['asunto'];
$mensaje = $_POST['mensaje'];
$archivo = $_FILES['hugo'];

//this block is important
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 25;

//our account
$mail->Username ='mail@gmail.com';
$mail->Password = '******';

//Add destinatary
$mail->AddAddress($para);
$mail->Subject = $asunto;
$mail->Body = $mensaje;
//Para adjuntar archivo
$mail->AddAttachment($archivo['tmp_name'], $archivo['name']);
$mail->MsgHTML($mensaje);

//Avisar si fue enviado o no y dirigir al index
if($mail->Send())
{
    echo'<script type="text/javascript">
            alert("Enviado Correctamente");
            window.location="http://localhost/maillocal/index.php"
         </script>';
}
else{
    echo'<script type="text/javascript">
            alert("NO ENVIADO, intentar de nuevo");
            window.location="http://localhost/maillocal/index.php"
         </script>';
}

help (Y)

  • 2
    Did you check the troubleshooting for PHPMailer? https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting – Eduardo Galván Apr 12 '16 at 15:14
  • 1
    SSL over port 25? Not too sure about that. Port 25 isn't (typically) a secure port. Try using port 465. – mferly Apr 12 '16 at 15:16
  • 2
    Possible duplicate of [PHPMailer: SMTP Error: Could not connect to SMTP host](http://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host) – callmemath Apr 12 '16 at 15:16
  • You're running an old version of PHPMailer and have based your code on an obsolete example. [Get the latest](https://github.com/PHPMailer/PHPMailer). – Synchro Apr 12 '16 at 17:50

0 Answers0