【问题标题】:Send email using online server in php [duplicate]在php中使用在线服务器发送电子邮件[重复]
【发布时间】:2018-10-04 15:31:11
【问题描述】:

我有电子邮件共享 PHP 代码。它对localserver(localhost) 非常有效。我已将此代码托管到在线服务器,但它无法正常工作且没有响应。如何解决这个问题?在这里检查我的代码..

if(isset($_POST['shareemail'])){
require "php-mailer-master/PHPMailerAutoload.php" ;
$mail = new PHPMailer;
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';// smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'funz4m05@gmail.com' ;                // SMTP username
$mail->Password = '******' ;                   // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->setFrom(funz4m05@gmail.com, 'mailer');
$mail->addAddress('to@gmail.com');               // Name is optional
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'this subject' ;
$mail->Body    = "<b>html</b>" ; // this is html format
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

    }

?> 

【问题讨论】:

  • “但不工作和任何响应”是什么意思?实际发生了什么?
  • 如果您想使用 gmail 发送电子邮件,请参考:github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
  • @John Conde 我没有收到任何错误......并且没有发送邮件......提交按钮后也是如此......没有任何更改。

标签: php email smtp


【解决方案1】:

您是否忘记了 $mail->setFrom() 上的 ' 或者它只是一个错字?

试试

$mail->setFrom('funz4m05@gmail.com', 'mailer');

【讨论】:

  • 抱歉弄错了我的代码..我已经在使用这个...
  • 我发现了 Sigma 所说的一个区别: //设置邮件服务器的主机名 $mail->Host = 'smtp.gmail.com'; // 使用 // $mail->Host = gethostbyname('smtp.gmail.com'); // 如果您的网络不支持 SMTP over IPv6
  • 不工作但我正在尝试 gethostbyname('smtp.gmail.com');
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-29
  • 1970-01-01
  • 1970-01-01
  • 2020-11-19
  • 2013-10-11
  • 1970-01-01
  • 2021-10-01
相关资源
最近更新 更多