2010-03-24 129 views
2

干草我使用的PHPMailer发送一些简单的电子邮件,但功能setFrom()方法似乎不起作用,即使代码我使用是直接从phpmails文档(http://phpmailer.worxware.com/index.php?pg=examplebmailPHPMailer的示数出与调用未定义的方法的PHPMailer :: setFrom()方法

这里我的错误

Call to undefined method PHPMailer::SetFrom() 

和我的脚本

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(); 

任何想法?

编辑

原来犯规存在于我的版本的PHPMailer的setFrom()方法的功能,我可以用

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

回答

8

精心设置这些值,有PHPMailer的多个版本各地。我从来没有完全明白哪个是哪个。无论如何,PHPMailer的5.1 this download肯定包含setFrom方法:

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

原来的功能setFrom()方法不存在(作为错误状态),然而,我可以通过使用$ MAIL->出发=“x”的设置$从变量和$ FROMNAME; – dotty 2010-03-24 15:59:39

+1

@dtyty您可能正在使用PHPMailer的不同版本(旧版本)。 – 2010-03-24 16:00:33

0

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

尝试使用版本佩卡建议,或这一个,并希望你的问题将消失。

相关问题