title: Sending mail from PHP gives Unrouteable address
body: <p>I have a Debian server running PHP and Exim4 (among other things of course).
  The PHP application is sending 1000s of emails every day all of which work fine, however I now have a new customer and my PHP/Exim4 has trouble sending to this account.</p>
  
  <p>PS I added the --at-- to stop crawlers finding the addresses.</p>
  
  <ol>
  <li>I checked the exim4 logs and found this:</li>
  </ol>
  
  <blockquote>
  <pre><code>2014-04-02 08:48:10 1WV7TW-0001Em-Od &lt;= support --at-- sobs.com.au H=localhost [127.0.0.1] P=esmtp S=1215 
  2014-04-02 08:48:11 1WV7TW-0001Em-Od ** az --at-- mentonegrammmar: Unrouteable address 
  2014-04-02 08:48:11 1WV7TW-0001Em-Od Completed
  </code></pre>
  </blockquote>
  
  <ol>
  <li><p>I then checked the routing in exim4 using:</p>
  
  <p>exim -d -f support --at-- sobs.com.au -bt az --at-- mentonegrammar</p></li>
  </ol>
  
  <blockquote>
  <pre><code>Exim version 4.80 uid=0 gid=0 pid=12506 D=fbb95cfd
  Berkeley DB: Berkeley DB 5.1.29: (October 25, 2011)
  Support for: crypteq iconv() IPv6 GnuTLS move_frozen_messages DKIM
  Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz dbmnz dnsdb dsearch nis nis0 passwd
  Authenticators: cram_md5 plaintext
  Routers: accept dnslookup ipliteral manualroute queryprogram redirect
  Transports: appendfile/maildir/mailstore autoreply lmtp pipe smtp
  Fixed never_users: 0
  Size of off_t: 8
  Compiler: GCC [4.7.2]
  Library version: GnuTLS: Compile: 2.12.20
  Runtime: 2.12.20
  Library version: PCRE: Compile: 8.31
  Runtime: 8.30 2012-02-04
  Total 13 lookups
  WHITELIST_D_MACROS: "OUTGOING"
  TRUSTED_CONFIG_LIST: "/etc/exim4/trusted_configs"
  changed uid/gid: forcing real = effective
  uid=0 gid=0 pid=12506
  auxiliary group list: none
  seeking password data for user "uucp": cache not available
  getpwnam() succeeded uid=10 gid=10
  changed uid/gid: calling tls_validate_require_cipher
  uid=101 gid=103 pid=12507
  auxiliary group list: none
  tls_validate_require_cipher child 12507 ended: status=0x0
  configuration file is /var/lib/exim4/config.autogenerated
  log selectors = 00000ffc 00612001
  trusted user
  admin user
  seeking password data for user "mail": cache not available
  getpwnam() succeeded uid=8 gid=8
  user name "root" extracted from gecos field "root"
  originator: uid=0 gid=0 login=root name=root
  sender address = root --at-- ds6419.hostname.net.au
  Address testing: uid=0 gid=103 euid=0 egid=103
  Testing az --at-- mentonegrammar
  Considering az --at-- mentonegrammar
  routing az --at-- mentonegrammar
  -------- hubbed_hosts router --------
  local_part=az domain=mentonegrammar
  checking domains
  expansion of "${if exists{/etc/exim4/hubbed_hosts}{partial-lsearch;/etc/exim4/hubbed_hosts}fail}"
  forced failure: assume not in this list
  hubbed_hosts router skipped: domains mismatch
  -------- dnslookup_relay_to_domains router --------
  local_part=az domain=mentonegrammar
  checking domains
  search_open: dsearch "/etc/exim4/virtual"
  search_find: file="/etc/exim4/virtual"
  key="mentonegrammar" partial=-1 affix=NULL starflags=0
  LRU list:
  5/etc/exim4/virtual
  End
  internal_search_find: file="/etc/exim4/virtual"
  type=dsearch key="mentonegrammar"
  file lookup required for mentonegrammar
  in /etc/exim4/virtual
  lookup failed
  mentonegrammar.net in "@:localhost:dsearch;/etc/exim4/virtual"? no (end of list)
  mentonegrammar.net in "empty"? no (end of list)
  mentonegrammar.net in "! +local_domains : +relay_to_domains"? no (end of list)
  dnslookup_relay_to_domains router skipped: domains mismatch
  -------- dnslookup router --------
  local_part=az domain=mentonegrammar
  checking domains
  cached no match for +local_domains
  cached lookup data = NULL
  mentonegrammar in "! +local_domains"? yes (end of list)
  R: dnslookup for az@mentonegrammar
  calling dnslookup router
  dnslookup router called for az --at-- mentonegrammar
  domain = mentonegrammar
  DNS lookup of mentonegrammar (MX) succeeded
  DNS lookup of mail.mentonegrammar (AAAA) gave NO_DATA
  returning DNS_NODATA
  DNS lookup of mail.mentonegrammar (A) succeeded
  58.96.103.231 in "0.0.0.0 : 127.0.0.0/8 : 192.168.0.0/16 :172.16.0.0/12 : 10.0.0.0/8 : 169.254.0.0/16 :255.255.255.255"? no
  (end of list)
  fully qualified name = mentonegrammar
  host_find_bydns yield = HOST_FOUND (2); returned hosts:
  mail.mentonegrammar 58.96.103.231 MX=5
  set transport remote_smtp
  queued for remote_smtp transport: local_part = az
  domain = mentonegrammar
  errors_to=NULL
  domain_data=NULL localpart_data=NULL
  routed by dnslookup router
  envelope to: az --at-- mentonegrammar
  transport: remote_smtp
  host mail.mentonegrammar [58.96.103.231] MX=5
  search_tidyup called
  =============== Exim pid=12506 terminating with rc=0 ===============
  az --at-- mentonegrammar
  router = dnslookup, transport = remote_smtp
  host mail.mentonegrammar [58.96.103.231] MX=5
  </code></pre>
  </blockquote>
  
  <p>This looks as though the routing is working perfectly.  I tried the application email again and still get the Unrouteable address error.</p>
  
  <ol>
  <li><p>Then I tried a command line email from the same server.</p>
  
  <p>echo "Test message" | mail -s "Test message" az --at-- mentonegrammar</p></li>
  </ol>
  
  <p>This email worked and arrived as required, but the email from my PHP application still fails.</p>
  
  <ol>
  <li>I checked the application:</li>
  </ol>
  
  <blockquote>
  <pre><code>$mime = new Mail_mime();
  $formattedHeaders = $mime-&gt;headers($headers);
  $mime-&gt;setHTMLBody($body);
  $content = $mime-&gt;get(array('html_charset' =&gt; 'utf-8'));
  $smtp = Mail::factory("smtp", array());
  $result = $smtp-&gt;send($headers["To"], $formattedHeaders, $content);
  </code></pre>
  </blockquote>
  
  <ol>
  <li><p>As mentioned there are 1000s of emails being successfully sent by this server and application.</p></li>
  <li><p>The IT at Mentone Grammar haven't indicated any problems receiving any other emails.</p></li>
  </ol>
  
  <p>In summary, I keep coming back to the 'Unrouteable address' error in the exim4 log, and the debug output indicating that the address is routable.  I can't help thinking there is some problem with the Exim4 config - but I just don't know.</p>
  
  <p>Can anybody point me in the right direction please?</p>