2010-03-24 25 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變量)並且提交成功。

嘗試使用版本佩卡建議,或這一個,並希望你的問題將消失。

相關問題