unable to send email using REST API build in php?

Posted by Pushpendra Kuntal on Stack Overflow See other posts from Stack Overflow or by Pushpendra Kuntal
Published on 2011-11-12T13:40:27Z Indexed on 2011/11/12 17:51 UTC
Read the original article Hit count: 552

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about rest