我已经尝试了一切,我不知道如何解决这个问题,所以,我正在使用这个 Swift Mailer 库来发送确认电子邮件。所以这是我的 index.php 中的代码
if($confirm){
//include the swift class
include_once 'inc/php/swift/swift_required.php';
//put info into an array to send to the function
$info = array(
'username' => $username,
'email' => $email,
'key' => $key);
//send the email
if(send_email($info)){
//email sent
$action['result'] = 'success';
array_push($text,'Thanks for signing up. Please check your email for confirmation!');
}else{
$action['result'] = 'error';
array_push($text,'Could not send confirm email');
}
}
而我的 send_email 函数在另一个 php 文件 functions.php
//send the welcome letter
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance(smtp.gmail.com,465,ssl)
->setUsername('my email here')
->setPassword('my password');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Welcome to Site Name');
$message ->setFrom(array('somedomain.com' => 'somethinghere'));
$message ->setTo(array($info['email'] => $info['username']));
$message ->setBody($body_plain_txt);
$message ->addPart($body, 'text/html');
$result = $mailer->send($message);
return $result;
}
我得到的错误是
致命错误:在第 31 行的 /srv/disk7/something/www/something/signup/inc/php/functions.php 中调用未定义的方法 Swift_MailTransport::setUsername()
我怎样才能解决这个问题?我是php的初学者。