【问题标题】:Empty page after sending mail with phpMailer使用 phpMailer 发送邮件后的空白页面
【发布时间】:2012-06-15 17:44:15
【问题描述】:

我正在尝试使用 phpMailer 发送邮件。这是我的代码:

<?php
  require_once('phpmailer/class.phpmailer.php');
  $mail = new PHPMailer(true);

  $mail->PluginDir = "phpmailer/";
  $mail->IsSMTP();
  $mail->SMTPAuth = true; // enable SMTP authentication
  $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
  $mail->Host = "smtp.gmail.com";
  $mail->Port = 465;
  $mail->Username = "xxx@gmail.com";
  $mail->Password = "xxxxx";

  $mail->SetFrom('yyyya@gmail.com', 'Nasze imie i nazwisko');

  $mail->AddAddress("email@anymail.pl"); // ADRESAT

  $mail->Subject = 'Test message';

  // w zmienną $text_body wpisujemy treść maila
  $text_body = "Hello, \n\n";
  $text_body .= "Sending succesfully, \n";
  $text_body .= "PHPMailer";

  $mail->Body = $text_body;

  if(!$mail->Send())
    echo "There has been a mail error <br>";
  echo $mail->ErrorInfo."<br>";

  // Clear all addresses and attachments
  $mail->ClearAddresses();
  $mail->ClearAttachments();
  echo "mail sent <br>";
?>

邮件未发送,在浏览器中我有空白页面,没有消息。这里有什么问题?

最好的问候, 达格纳

【问题讨论】:

    标签: php phpmailer


    【解决方案1】:

    邮件未发送,在浏览器中我有空白页面,没有消息。 这里有什么问题?

    尝试设置错误检查(仅用于开发):

    ini_set('display_errors',  true);
    error_reporting(1);
    

    将以上两行放在页面顶部。这应该会给你一些信息,例如究竟出现了什么错误。

    更新

    我像这样修改了class.smtp.php 文件的Connect 函数,让它为自己工作:

    public function Connect($host, $port = 0, $tval = 30) {
    
      $host = "ssl://smtp.gmail.com";
      $port = 465;
    
      // other code
    

    我的电子邮件发送代码是有效的;

    require("PHPMailer_v5.1/class.phpmailer.php");
    
    $mail = new PHPMailer();
    $mail->IsSMTP(); // send via SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "xxxxxxxxx@gmail.com"; // SMTP username
    $mail->Password = "xxxxxxxxx"; // SMTP password
    $webmaster_email = "xxxxxx@gmail.com"; //Reply to this email ID
    $email = "xxxxxxx@gmail.com"; // Recipients email ID
    $name = "Sarfraz"; // Recipient's name
    $mail->From = $webmaster_email;
    $mail->FromName = "Local Mail from Sarfraz";
    $mail->AddAddress($email, $name);
    $mail->AddReplyTo($webmaster_email,"Webmaster");
    $mail->WordWrap = 50; // set word wrap
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = "I am a local mail !";
    $mail->Body = "Hey What's up? Have fun :)"; //HTML Body
    
    if(!$mail->Send())
    {
      echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
      echo "Message has been sent";
    }
    

    【讨论】:

    • 致命错误:未捕获的异常 'phpmailerException' 带有消息“SMTP 错误:无法连接到 SMTP 主机。”在 /(...)/public_html/phpmailer/class.phpmailer.php:705 堆栈跟踪:#0 /(...)/public_html/phpmailer/class.phpmailer.php(613): PHPMailer->SmtpConnect() #1 /export/w3home/w3biocon/public_html/phpmailer/class.phpmailer.php(516): PHPMailer->SmtpSend('Date: Fri, 15 J...', 'Cze????, chyba ... ') #2 /export/w3home/w3biocon/public_html/send_mail.php(29): PHPMailer->Send() #3 {main} 在 /export/w3home/w3biocon/public_html/phpmailer/class.phpmailer.php 中抛出第 705 行
    • @user1109813:尝试将host 地址指定为ssl://smtp.gmail.com 例如,而不是$mail-&gt;Host = "smtp.gmail.com";,尝试$mail-&gt;Host = "ssl://smtp.gmail.com";
    • @user1109813 是的,现在你得到了错误SMTP Error: Could not connect to SMTP host。现在你可以谷歌“通过 php 和 gmail 发送电子邮件”\o/
    • @Shikiryu,我做到了,但在每个示例中,设置都与我的代码中的一样。这是我的 phpinfo:bioconference.wnb.uz.zgora.pl/phpinfo.php。也许有任何服务器设置?
    • @user1109813:很高兴知道 :)
    猜你喜欢
    • 2013-11-04
    • 2015-09-23
    • 1970-01-01
    • 2015-09-08
    • 2013-11-29
    • 1970-01-01
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多