Reputation: 46
I'm new here in this forum and a little newbie on the coding php aswell.
so here is the subject, I'm using phpMailer to send an email. But it only works on localhost. I was working fine with it and when I uploaded the project to the webhost, it stopped sending properly right away. And I didn't even changed one single line.
so here it is.
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "Nenhum argumento fornecido.";
return false;
}
require 'class.phpmailer.php';
require 'PHPMailerAutoload.php';
$mail = new PHPmailer();
$mail->setLanguage('pt');
$host = 'smtp.live.com';
$username = '[email protected]';
$password = 'mypassword';
$port = 587;
$secure = 'tls';
$from = $username;
$fromName = 'Pedido-'.$_POST['name'];
$mail->isSMTP();
$mail->Host = $host;
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->Port = $port;
$mail->SMTPSecure = $secure;
$mail->From = $from;
$mail->FromName = $fromName;
$mail->addReplyTo($from, $fromName);
$mail->addAddress('[email protected]', $_POST['name']);
$mail->isHTML(true);
$mail->Charset = 'utf-8';
$mail->WordWrap = 70;
$mail->Subject = 'Envios do formulario';
$mail->Body = '<b>Nome:</b> '.$_POST['name'];
$mail->Body .= '<br><b>Responder para:</b> '.$_POST['email'];
$mail->Body .= '<br><b>Telefone:</b> '.$_POST['phone'];
$mail->Body .= '<br><b>Mensagem:</b> <br>'.$_POST['message'];
$mail->AltBody = '';
$send = $mail->Send();
return 0;
?>
It works perfecly fine when on localhost.
Upvotes: 2
Views: 998
Reputation: 3204
You didn't mention whether you checked this or not, but it's possible your host has a firewall that is blocking connections on that port. If it worked locally and stopped working when uploading it to your host, that's certainly a possibility. If they give you access to configure that, make sure outbound connections to that port are enabled. You may also want to check if the SMTP server returned a response at all. That can often tell you a lot about what happened.
Upvotes: 1
Reputation: 664
Maybe your local server and remote server have different PHP versions, so check it first and also
FILTER_VALIDATE_EMAIL
Filter Validation is only available for PHP Versions (PHP 5 >= 5.2.0) according to documentation. So make sure your version is correct.
AND also try this
comment this line in file and try again .. i think you are not using it
//require 'PHPMailerAutoload.php';
Upvotes: 0