duanci5913 2014-12-07 04:15
浏览 93
已采纳

phpMailer仅适用于localhost

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   = 'myemail@hotmail.com';
$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('toemail@gmail.com', $_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.

  • 写回答

2条回答 默认 最新

  • dongxiao3694 2014-12-07 06:23
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址