调用未定义方法的PHPMailer异常PHPMailer :: SetFrom() [英] PHPMailer erroring out with Call to undefined method PHPMailer::SetFrom()

查看:1525
本文介绍了调用未定义方法的PHPMailer异常PHPMailer :: SetFrom()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

干草我正在使用PHPMailer发送一些简单的电子邮件,但是即使我使用的代码是直接从phpmails文档( http://phpmailer.worxware.com/index.php?pg=examplebmail



这里我的错误

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

和我的脚本

  require_once( 'INC / PHPMailer的/ class.phpmailer.php'); 
$ mail = new PHPMailer(); //默认使用phpmail()
$ body = $ message;
$ mail-> SetFrom('tell-a-friend@domain.com','告诉朋友');
$ mail-> AddAddress($ to_email,$ to);
$ mail-> Subject =告诉朋友;
$ mail-> MsgHTML($ body);
$ mail-> Send();

任何想法?



编辑

证明在我的phpmailer版本中不存在SetFrom()函数,我可以使用

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


解决方案

小心点,PHPMailer有多个版本。我从来不知道哪个是哪个。无论如何,PHPMailer 5.1的此下载肯定包含一个 setFrom 方法:

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


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)

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('tell-a-friend@domain.com', '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

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

解决方案

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

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

这篇关于调用未定义方法的PHPMailer异常PHPMailer :: SetFrom()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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