php PHPMailer 错误调用未定义的方法 PHPMailer::SetFrom()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2509145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:45:23  来源:igfitidea点击:

PHPMailer erroring out with Call to undefined method PHPMailer::SetFrom()

phpemailphpmailer

提问by dotty

Hay I'm using PHPMailer to send some simple emails, however the function SetFrom() doesn't seem to work, even though the code I'm using is straight from phpmails docs (http://phpmailer.worxware.com/index.php?pg=examplebmail)

我正在使用 PHPMailer 发送一些简单的电子邮件,但是函数 SetFrom() 似乎不起作用,即使我使用的代码直接来自 phpmails 文档 ( http://phpmailer.worxware.com/index .php?pg=examplebmail)

Here my error

这是我的错误

Call to undefined method PHPMailer::SetFrom()

and my script

和我的脚本

require_once('inc/phpmailer/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $message;
$mail->SetFrom('[email protected]', 'tell a friend');
$mail->AddAddress($to_email, $to);
$mail->Subject = "tell a friend";
$mail->MsgHTML($body);
$mail->Send();

Any ideas?

有任何想法吗?

EDIT

编辑

turns out the SetFrom() function doesnt exist in my version of phpmailer, i can set these values using

原来我的 phpmailer 版本中不存在 SetFrom() 函数,我可以使用设置这些值

$mail->From = '';
$mail->FromName = '';

回答by Pekka

Careful, there are multiple versions of PHPMailer around. I've never quite understood which is which. Anyway, this downloadof PHPMailer 5.1 definitely contains a setFrommethod:

小心,有多个版本的 PHPMailer。我一直不太明白哪个是哪个。无论如何,PHPMailer 5.1 的这个下载肯定包含一个setFrom方法:

  public function SetFrom($address, $name = '',$auto=1) {   

回答by Roadmaster

I concur with Pekka; I downloaded PHPMailer from here, used your code as-is (well, I assigned the $to_email, $to and $message variables) and the submission was successful.

我同意佩卡的观点;我从这里下载了 PHPMailer ,按原样使用了您的代码(好吧,我分配了 $to_email、$to 和 $message 变量)并且提交成功。

Try using the version Pekka suggested, or this one, and hopefully your problem will go away.

尝试使用 Pekka 建议的版本或这个版本,希望您的问题会消失。