Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Linux email configuration - multiple domains

    We have a webserver that hosts 2 domains.

    PHP version: 5.3.3-7+squeeze14

    Apache info:
    Server version: Apache/2.2.16 (Debian)
    Server built: Nov 30 2012 08:33:45

    These are configured in these directories:

    /etc/apache2/sites-available
    /etc/apache2/sites-enabled
    /etc/apache2/ports.conf

    Everything responds correctly in the web browser, except we're having problems with sending email.

    I have exim4 set up for email but I'm not sure if I have it configured correctly. Before I set up the 2nd domain (www.domain2.us), email was working fine from the original domain (www.domain1.com). After I set up domain2.us, email stopped working for domain1.com (& didn't work for domain2.us).

    I tried dpkg-reconfigure exim4-config several times and eventually got domain2.us and domain1.com to be able to send email from a simple test script that looks like this:

    domain1.com:
    PHP Code:
    <?php
    $headers 
    'From: [B]webmaster@domain1.com[/B]' "\r\n" .
        
    'Reply-To: [B]webmaster@domain1.com[/B]' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

    // The message
    $message "[B]domain1.com[/B]\nLine 1\r\nLine 2\r\nLine 3";

    // In case any of our lines are larger than 70 characters, we should use wordwrap()
    $message wordwrap($message70"\r\n");

    // Send
    $suc mail('myemail@hotmail.com''My Subject'$message);

    echo 
    '[' $suc ']';
    ?>
    domain2.us:
    PHP Code:
    <?php
    $headers 
    'From: [B]webmaster@domain2.us[/B]' "\r\n" .
        
    'Reply-To: [B]webmaster@domain2.us[/B]' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

    // The message
    $message "[B]domain2.us[/B]\nLine 1\r\nLine 2\r\nLine 3";

    // In case any of our lines are larger than 70 characters, we should use wordwrap()
    $message wordwrap($message70"\r\n");

    // Send
    $suc mail('myemail@hotmail.com''My Subject'$message);

    echo 
    '[' $suc ']';
    ?>

    However, when the emails come in the sender for domain1.com shows up as:

    webmaster@domain1

    emails from domain2.us show up as:

    www-data@domain1

    How can I get the ones from domain2.us too show up as being from webmaster@domain2 instead of www-data@domain1?

    Thanks!

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    You need to be passing your custom headers in the mail() function's 4th argument:
    PHP Code:
    mail('myemail@hotmail.com''My Subject'$message$headers); 
    And make sure you remove the [B] tags you have in the headers currently.

    Alternatively, you can create/use an SMTP account for each domain to send email through so it will always be the correct domain & username.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •