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

那年仲夏 提交于 2019-12-02 04:39:51

问题


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 = '';

回答1:


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) {   



回答2:


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.

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



来源:https://stackoverflow.com/questions/2509145/phpmailer-erroring-out-with-call-to-undefined-method-phpmailersetfrom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!