Hola,
Gracias por contestar. Pues mira, usé el smtp de Google y el usuario y contraseña de una cuenta de Gmail que tengo para hacer pruebas. Pego aquí el código que tengo hecho y que en local no tengo problemas.
Probé también con 'tls' y puerto 587 sin ningun éxito. También probé con el siguiente codigo sin éxito: https://gist.github.com/emmgfx/7762b85e924c24f7575fe36c315ff0e7
Añadiendo esto:
Que tampoco lo conseguí hacerlo funcionar en mi hosting.
Gracias,
Saludos,
Gracias por contestar. Pues mira, usé el smtp de Google y el usuario y contraseña de una cuenta de Gmail que tengo para hacer pruebas. Pego aquí el código que tengo hecho y que en local no tengo problemas.
Código (php) [Seleccionar]
<?php
require ('phpmailer/class.phpmailer.php');
require ('phpmailer/class.smtp.php');
if(isset($_POST['submit'])){
// recoge nombre, mail archivo adjunto y comentario desde formulario HTML
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$file = $_FILES['attachment'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 3;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com"; // SMTP a utilizar
$mail->Port = 465;
//Mail y pass a utilizar
$mail->Username = "micuenta@gmail.com";
$mail->Password = "mipassword";
$mail->From = $email;
$mail->FromName = "Formulario";
$mail->AddAddress ("micuenta@gmail.com");
$mail->IsHTML(true);
$mail->Subject = "Formulari de contacte de $name";
// Inicio del mensaje HTML
$mail->Body = "
<html>
<body>
<table style='width:600px;'>
<tbody>
<tr>
<td style='width:150px'><strong>Nom i cognoms: </strong></td>
<td style='width:400px'>$name</td>
</tr>
<tr>
<td style='width:150px'><strong>Email: </strong></td>
<td style='width:400px'>$email</td>
</tr>
<tr>
<td style='width:150px'><strong>Comentari: </strong></td>
<td style='width:400px'>$message</td>
</tr>
</tbody>
</table>
</body>
</html>
";
// Fin del mensaje HTML
$mail->AddAttachment($file['tmp_name'], $file['name']);
if ($mail->Send())
echo "<script>alert('Formulari enviat. Li respondrem aviat.');location.href ='https://www.xxxxx.yyy';</script>";
else
echo "<script>alert('Error a l'hora d'enviar el formulari');location.href ='javascript:history.back()';</script>";
}
?>
Probé también con 'tls' y puerto 587 sin ningun éxito. También probé con el siguiente codigo sin éxito: https://gist.github.com/emmgfx/7762b85e924c24f7575fe36c315ff0e7
Añadiendo esto:
Código [Seleccionar]
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPSecure = 'tls'; # SSL is deprecated
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'Plesk',
)
);
Que tampoco lo conseguí hacerlo funcionar en mi hosting.
Gracias,
Saludos,