phpmailer错误“无法实例化邮件功能”

我正在使用对mail()用户ID稍加修改的基本示例,但出现错误“邮件错误:无法实例化邮件功能”


如果我使用邮件功能-


mail($to, $subject, $message, $headers);

它工作正常,尽管我在发送html时遇到问题,这就是为什么我尝试使用PHPMailer的原因。


这是代码:


<?php

require_once('../class.phpmailer.php');


    $mail             = new PHPMailer(); // defaults to using php "mail()"

    $body             = file_get_contents('contents.html');

    $body             = eregi_replace("[\]",'',$body);

        print ($body ); // to verify that I got the html

    $mail->AddReplyTo("reply@domain.com","my name");

    $mail->SetFrom('from@domain.com', 'my name');

    $address = "to@domain.com";

    $mail->AddAddress($address, "her name");

    $mail->Subject    = "PHPMailer Test Subject via mail(), basic";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";

    $mail->MsgHTML($body);

    $mail->AddAttachment("images/phpmailer.gif");      // attachment

    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment


    if(!$mail->Send()) {

        echo "Mailer Error: " . $mail->ErrorInfo;

    } else {

        echo "Message sent!";

    }

?>


人到中年有点甜
浏览 576回答 3
3回答

一只名叫tom的猫

$mail->AddAddress($address, "her name");应该更改为$mail->AddAddress($address);这适用于我的情况。
打开App,查看更多内容
随时随地看视频慕课网APP