代码之家  ›  专栏  ›  技术社区  ›  Talha Bin Shakir

PHP发送邮件错误

  •  3
  • Talha Bin Shakir  · 技术社区  · 17 年前

    请帮助我,我是PHP新手,从过去5个小时以来,我一直在尝试SEMD邮件,现在真的很累了。谢谢。

    这是我的密码。我正在使用Gmail帐户。

    include("class.phpmailer.php");
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
    
    $mail             = new PHPMailer();
    
    $body             = $mail->getFile('contents.html');
    $body             = eregi_replace("[\]",'',$body);
    
    $mail->IsSMTP();
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
    
    $mail->Username   = "hussaintalha@gmail.com";  // GMAIL username
    $mail->Password   = "xxxxxxxx";            // GMAIL password
    
    $mail->AddReplyTo("hussaintalha@gmail.com","First Last");
    
    $mail->From       = "hussaintalha@gmail.com.com";
    $mail->FromName   = "First Last";
    
    $mail->Subject    = "PHPMailer Test Subject via gmail";
    
    //$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->WordWrap   = 50; // set word wrap
    
    $mail->MsgHTML($body);
    
    $mail->AddAddress("hussaintalha@gmail.com", "John Doe");
    
    $mail->AddAttachment("images/phpmailer.gif");             // attachment
    
    $mail->IsHTML(true); // send as HTML
    
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }
    ?>
    

    当我运行我的文件时,我得到这个错误:

    警告:fopen(contents.html) [函数.fopen]:打开失败 流:中没有此类文件或目录 d:\xampapplite\htdocs\webeng\class.phpmailer.php 在线1870

    警告:fsockopen()) [函数.fsockopen]:无法 连接到ssl://smtp.gmail.com:465 (找不到套接字传输 “ssl”-您忘记启用它了吗? 配置php时?)在里面 d:\xampapplite\htdocs\webeng\class.smtp.php 第122行邮件程序错误:SMTP错误: 无法连接到SMTP主机。

    2 回复  |  直到 17 年前
        1
  •  4
  •   markus    17 年前

    首先,当你收到错误信息的时候,那就太好了!因为在90%的情况下,你会发现其他人也有他们,因此你会在互联网上找到关于这个错误信息的大量信息。

    所以第一步当你收到一条你还不知道的错误信息时,总是打开谷歌并复制粘贴到那里。但是,去掉任何与系统唯一相连的路径或其他东西。

    然后是关于你的错误。尤其是xampp-light不支持SSL。也许您可以先尝试一个更简单的sendmail示例。像一个非常小的,然后一步一步地增加它。 这就是我一直在做的,当我不知道为什么有些事情不起作用的时候。我从一行开始,看看它做了什么,然后再添加另一行,以此类推。

    假设您从这个开始,看看它是否有效:

    <?php
    
    include("class.phpmailer.php");
    
    $mail             = new PHPMailer();
    
    $mail->IsSMTP();
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "hussaintalha@gmail.com";  // GMAIL username
    $mail->Password   = "xxxxxxxx";            // GMAIL password
    
    $mail->From       = "hussaintalha@gmail.com";
    $mail->Subject    = "PHPMailer Test Subject via gmail";
    $mail->Body       = "Hi, this is a test";           
    $mail->AddAddress("hussaintalha@gmail.com", "Hussain");
    
    $mail->send();
    ?>
    

    哦,顺便说一句,你的邮件有一个网站太多了!

        2
  •  4
  •   Mihai Limbășan    17 年前

    PHP安装(从外观上看,是XAMPP)不支持SSL。确保线路

    extension=php_openssl.dll
    

    是 不 在php.ini中发表了评论,请重新启动apache,如果仍然不起作用,请尝试将ssleay32.dll和libeay32.dll从php目录覆盖(或复制)到apache的二进制(.exe)目录中,然后重新启动apache。

    推荐文章