unable to send email using REST API build in php?
- by Pushpendra Kuntal
i am designing REST API in php. I want to send a page to send email. This is my code to send email:
$app->get('/sendemail', function () {
<?php
require_once "Mail.php";
$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHey Kuntal, 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>");
}
?>
});
My code of sending email is working if i check this into my separate file. But this code is not working in API. please suggest me what should i do for this?