title: Unable to send email using REST API build in php?
body: <p>I am designing REST API in php. I am using slim framework to design API.  I want to  send a page to send email.  This is my code to send email:</p>
  
  <p>
  
  <pre><code>$app-&gt;get('/sendemail', function () {
  
  
  
   require_once "Mail.php";
   $from = "Sender &lt;sender@domain.com&gt;";
   $to = "Recipient &lt;recipient@anotherDomain.com&gt;";
   $subject = "Hi!";
   $body = "Hi,\n\nHey Recipient, you done it...";
   $host = "my host";
   $username = "myuserid";
   $password = "password";
   $headers = array ('From' =&gt; $from,
     'To' =&gt; $to,
     'Subject' =&gt; $subject);
   $smtp = Mail::factory('smtp',
     array ('host' =&gt; $host,
       'auth' =&gt; true,
       'username' =&gt; $username,
       'password' =&gt; $password));
  
   $mail = $smtp-&gt;send($to, $headers, $body);
  
   if (PEAR::isError($mail)) {
     echo("&lt;p&gt;" . $mail-&gt;getMessage() . "&lt;/p&gt;");
    } else {
     echo("&lt;p&gt;Message successfully sent!&lt;/p&gt;");
    }
   ?&gt;
  });
  </code></pre>
  
  <p>My code of sending email is working if i check this into my separate file.  But this code is not working in API.</p>
  
  <p>This is error which is generating :-</p>
  
  <p><img src="https://i.stack.imgur.com/yugug.png" alt="enter image description here"></p>
  
  <p>please suggest me what should i do for this?</p>