如何使用PHPmailer?帮助我使用它的API

时间:2010-11-28 19:38:01

标签: php smtp phpmailer

我创建了一个PHP页面,让页面自动发送给用户,我尝试使用PHPMailer,但它只说“SMTP ERROR:无法访问主机或类似的东西

这是我的代码:

PHPMailer x = new PHPMailer();
x->isSMTP();
x->Host = myhost;
x->Port = myport;
x->AddAddress(recipientAddress);
x->From = myEmail;
x->Username = username;
x->Password = password;
x.Send();

3 个答案:

答案 0 :(得分:1)

这里是您的代码的快速修复

$mail = new PHPMailer();
$mail->IsMail();
$mail->setCharset = "UTF-8";
$mail->Host = "localhost";
//    $mail->Port = "587"; you don't need it now 
    $mail->AddAddress("recipientAddress");
    $mail->setFrom = "myEmail";
    $mail->Subject = "Subject";
    $mail->Username = "username";
    $mail->Password = "password";
    $mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                           // 1 = errors and messages
                           // 2 = messages only

    $mail->Send();

所以现在您将获得更多调试消息并跟踪您的错误并修复它们:)

更新:好的很容易:

函数$ mail-> IsMail();表示必须使用mail()函数发送信件。其他方法是:

  

IsSendmail - 通过sendmail命令。

     

IsQmail - 直接通过qMail MTA。

     

IsSMTP - 通过SMTP服务器。

答案 1 :(得分:0)

尝试删除isSMTP行,以便它将使用PHP中配置的邮件设置。

答案 2 :(得分:0)

这看起来您在www服务器上的SMTP设置是错误的。

检查您是否可以使用您指定的SMTP配置发送电子邮件 - 如果不是:

  • 是否在myhost上运行了一个SMTP服务器:myport
  • 它是否在您使用的界面上进行通话?
  • 是否配置为从主机接受邮件?
  • 是否已将 接收者
  • 接受邮件