dpii73380 2012-06-15 08:36
浏览 81
已采纳

使用phpMailer发送邮件后的空页面

I'm trying to send mail using phpMailer. It's my code:

<?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, 

";
  $text_body .= "Sending succesfully, 
";
  $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>";
?>

Mail didn't send and in browser i have empty page, without message. What is here wrong?

Best regards, Dagna

  • 写回答

1条回答 默认 最新

  • dourou9477 2012-06-15 08:40
    关注

    Mail didn't send and in browser i have empty page, without message. What is here wrong?

    Try setting error checking on (for development only):

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

    Put above two lines on top of your page. This should give you some message now eg what error is coming up exactly.

    update

    I modified the class.smtp.php file's Connect function like this to get it working for myself:

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

    And my email sending code was which works is;

    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";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法