title: Postfix sendmail works from CL but not from PHP using Office365
body: <p>I have been trying to use Office365 SMTP relay for a web server running postfix. I need to be able to send messages from my Office365 domain to other addresses in the domain, so I don't think port 25 anonymous SMTP is going to work.</p>
  
  <p>If I run</p>
  
  <pre><code>echo "testing" | sendmail -fuser@mydomain.com me@mydomain.com
  </code></pre>
  
  <p>Then the message goes through (provided that user is listed in sasl_passwd)</p>
  
  <p>However if I run a simple PHP script such as this:</p>
  
  <pre><code>&lt;?php
  $to = "me@mydomain.com";
  $subject = "Test";
  $message = "test from PHP";
  $from = "user@mydomain.com";
  $headers = "From:" . $from;
  mail($to,$subject,$message,$headers);
  echo "Mail Sent.";
  ?&gt;
  </code></pre>
  
  <p>Then the delivery is bounced with</p>
  
  <pre><code>550 5.7.1 Client does not have permissions to send as this sender
  </code></pre>
  
  <p>I have read that the empty from=&lt;> value (which I can see in the logs) is the cause of the problem, but I don't understand how to change that to anything from postfix settings. Am I understanding correctly that postfix relay settings are correct if the command-line works? Is there some other step for PHP configuration that I am missing?</p>
  
  <p>From looking at the log file, it appears as though two messages are generated each time the PHP script is run. One has the correct from address and the other is empty.</p>
  
  <p>Let me know if you need any other information. Thanks in advance.</p>
  
  <p>-Seth</p>