我正在用 php 设计 REST API。我正在使用超薄框架来设计 API。我想发送一个页面来发送电子邮件。这是我发送电子邮件的代码:
$app->get('/sendemail', function () {
require_once "Mail.php";
$from = "Sender <sender@domain.com>";
$to = "Recipient <recipient@anotherDomain.com>";
$subject = "Hi!";
$body = "Hi,\n\nHey Recipient, you done it...";
$host = "my host";
$username = "myuserid";
$password = "password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
});
如果我将其签入我的单独文件,我的发送电子邮件代码就可以工作。但是这段代码在 API 中不起作用。
这是正在生成的错误:-
请建议我该怎么做?