phpmailer错误:无法实例化邮件功能 [英] phpmailer ERROR :Could not instantiate mail function

查看:2269
本文介绍了phpmailer错误:无法实例化邮件功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用localhost WAMP服务器(Windows)进行虚拟主机。我收到以下错误。

I am using localhost WAMP server (Windows) for webhosting. I am getting the following error.


phpmailer错误:无法实例化邮件功能。

phpmailer ERROR :Could not instantiate mail function.

我尝试了很多解决方案,但对我来说没有任何效果。

I have tried many solutions but nothing worked for me.

    $mailer = new PHPMailer();
    $mailer->IsMAIL();
    $mailer->CharSet = 'utf-8';
    $mailer->AddAddress($formvars['email'],$formvars['name']);
    $mailer->Subject = "Your registration with ".$this->sitename;
    $mailer->From = $this->GetFromAddress();        
    $confirmcode = $formvars['confirmcode'];
    $confirm_url = $this->GetAbsoluteURLFolder().'/confirmreg.php?code='.$confirmcode;
    $mailer->Body ="Hello ".$formvars['name']."\r\n\r\n".
    "Thanks for your registration with ".$this->sitename."\r\n".
    "Please click the link below to confirm your registration.\r\n".
    "$confirm_url\r\n".
    "\r\n".
    "Regards,\r\n".
    "Webmaster\r\n".
    $this->sitename;

    if(!$mailer->Send())
    {
        $this->HandleError("Failed sending registration confirmation email.".$mailer->ErrorInfo);
        //echo "Mailer Error: " . $mailer->ErrorInfo;
        return false;
    }
    return true;

如何诊断此错误?

推荐答案

$ mailer-> IsMAIL(); 告诉 PHPMailer PHP mail() 电子邮件传递功能。它在Unix类操作系统上运行,但不在Windows上,因为Windows的桌面版本不安装SMTP服务器(在安装光盘上可用)。

$mailer->IsMAIL(); tells PHPMailer to use the PHP mail() function for emails delivery. It works out of the box on Unix-like OSes but not on Windows because the desktop versions of Windows do not install a SMTP server (it is available on the installation disc).

为了使其在Windows上工作,您必须更改PHP配置。您可以编辑 php.ini (配置将在全局应用),也可以使用函数 ini_set() 只对当前脚本的当前执行进行更改。

In order to make it work on Windows you have to change the PHP configuration. Either you edit php.ini (the configuration will apply globally) or you can use function ini_set() to change it only for current execution of the current script.

最好的方法是更改​​ php.ini 。您可以在PHP的安装目录或Windows的目录中找到它。检查PHP函数 phpinfo()的输出,以找出其确切位置。

The best way is to change php.ini. You can find it in the PHP's installation directory or in the Windows's directory. Check the output of PHP function phpinfo() to find out its exact location.

打开 php.ini 在文本编辑器(你用来编写代码是最好的),并搜索一个如下所示的部分:

Open php.ini in a text editor (the one you use to write the code is the best) and search for a section that looks like this:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

对于 SMTP ,请使用公司邮件服务器的名称或IP地址。或者你的ISP的邮件服务器,如果你在家里。或者检查您的电子邮件客户端的配置。

For SMTP, use the name or the IP address of your company's mail server. Or your ISP's mail server if you are at home. Or check the configuration of your email client.

smtp_port 25 标准 SMTP 587 如果服务器使用 SSL 加密其通信。

The smtp_port is either 25 for standard SMTP or 587 if the server uses SSL to encrypt its communication.

还取消注释 sendmail_from 设置(如果已注释掉) ; 从开始行),并将您的电子邮件地址放在那里。

Also uncomment the sendmail_from setting if it is commented out (remove the ; from the beginning of line) and put your email address there.

阅读更多有关发送的PHP配置在文档页面上的Windows上的电子邮件。

Read more about the PHP configuration for sending emails on Windows on the documentation page.

另一个选项是在计算机上安装SMTP服务器。您可以在Windows安装光盘上找到一个,或者您可以使用第三方解决方案。

Another option is to install a SMTP server on the computer. You can find one on the Windows installation disc or you can use a third-party solution.

如果您选择不在您甚至不需要修改 php.ini 的计算机上安装SMTP服务器。您可以更改脚本的代码以使用SMTP服务器:

If you choose to not install a SMTP server on the computer you don't even need to modify php.ini. You can change the code of the script to use a SMTP server:

$mailer = new PHPMailer();

$mailer->IsSMTP();
$mailer->Host = "mail.example.com";
$mailer->Port = 25;

检查

Check this PHPmailer example for all the settings and their meaning.

如果SMTP服务器使用SMTP认证,那么这个PHPmailer的例子就是/examples/smtp.phpsrel =nofollow> (网络邮件提供商做它,您的ISP或您的公司可能会做或可能不这样做),那么您还必须添加:

If the SMTP server uses SMTP authentication (the webmail providers do it, your ISP or your company might do it or might not do it) then you have to also add:

$mail->SMTPAuth = true;
$mail->Username = "yourname@example.com";
$mail->Password = "yourpassword";

例如,如果您使用Gmail的SMTP服务器,请使用您的Gmail电子邮件地址和密码。将Gmail替换为Hotmail或Yahoo!或您的网络邮件提供商或您上述的公司。

If you use Gmail's SMTP server, for example, then use your Gmail email address and password. Replace "Gmail" with "Hotmail" or "Yahoo!" or your webmail provider or your company in the sentence above.

这篇关于phpmailer错误:无法实例化邮件功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆