Sending with Multiple Domain Suffixes from Single Apache Server Box

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Sending with Multiple Domain Suffixes from Single Apache Server Box

certified
How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain")

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
   [hidden email] sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
   [hidden email] sending from  /var/www/html/another needs mail sent from
[hidden email]
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Note that I don't want to receive email on my MX.






--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Fazzina, Angelo

Hi,

i am not too savvy, but i think you could do this in PHP or in Postfix.

My guess is, if you know what the "returndomain" is from using PHP code you could add it to the transport file maybe, and run postmap to update transport file ?


I assume you are pulling the "returndomain" from your PHP code to find it in the first place, if so can you just write code to insert it where you want when calling the mail(x,y,...) function ?


Is this the type of code you are doing as an example ?


$body="Hello ". $row['First_N']."\n\nPlease remember you have the following appointment scheduled for today.\n\nDate: $month/$day/$year \nTime: $time $showroom \nWith: ".$row['F_Name']." ". $row['L_Name']."\n\nFor more details on your appointment or to cancel your appointment, please go to the link below.\n\nhttp://uconn.edu/secure_per/index.php";

              $from = "[hidden email]";

              $headers = "From: $from";

             

              //***********************

              //PREPARE EMAIL HEADER

              $headers = array ('From' => $from,

              'To' => $to,

              'Subject' => $subject);

              //SEND EMAIL

              $mail = $smtp->send($to, $headers, $body);

              //THIS APPEARS TO CHECK FOR ERRORS IN THE EMAIL BEING SENT

              if (PEAR::isError($mail)) {

                             $failed++;

              }

              else {

                             $success++;

              }

              //***********************

             

             

              //mail($to,$subject,$body,$headers);

              //echo "<P>$message</P>";

              $i++;


Not sure i am any help or confusing the matter, you let me know.
-ALF


From: [hidden email] <[hidden email]> on behalf of certified <[hidden email]>
Sent: Tuesday, October 10, 2017 3:23 PM
To: [hidden email]
Subject: Sending with Multiple Domain Suffixes from Single Apache Server Box
 
How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain")

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
   [hidden email] sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
   [hidden email] sending from  /var/www/html/another needs mail sent from
[hidden email]
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Note that I don't want to receive email on my MX.






--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Fazzina, Angelo

Umm.... forget what i said about transport.


check this out

http://www.postfix.org/ADDRESS_REWRITING_README.html


This sounds like your idea :

Replace an internal address by an external address. For example, replace "[hidden email]" by "[hidden email]" when sending mail from a home computer to the Internet.




From: [hidden email] <[hidden email]> on behalf of Fazzina, Angelo <[hidden email]>
Sent: Tuesday, October 10, 2017 3:54 PM
To: certified; [hidden email]
Subject: Re: Sending with Multiple Domain Suffixes from Single Apache Server Box
 

Hi,

i am not too savvy, but i think you could do this in PHP or in Postfix.

My guess is, if you know what the "returndomain" is from using PHP code you could add it to the transport file maybe, and run postmap to update transport file ?


I assume you are pulling the "returndomain" from your PHP code to find it in the first place, if so can you just write code to insert it where you want when calling the mail(x,y,...) function ?


Is this the type of code you are doing as an example ?


$body="Hello ". $row['First_N']."\n\nPlease remember you have the following appointment scheduled for today.\n\nDate: $month/$day/$year \nTime: $time $showroom \nWith: ".$row['F_Name']." ". $row['L_Name']."\n\nFor more details on your appointment or to cancel your appointment, please go to the link below.\n\nhttp://uconn.edu/secure_per/index.php";

              $from = "[hidden email]";

              $headers = "From: $from";

             

              //***********************

              //PREPARE EMAIL HEADER

              $headers = array ('From' => $from,

              'To' => $to,

              'Subject' => $subject);

              //SEND EMAIL

              $mail = $smtp->send($to, $headers, $body);

              //THIS APPEARS TO CHECK FOR ERRORS IN THE EMAIL BEING SENT

              if (PEAR::isError($mail)) {

                             $failed++;

              }

              else {

                             $success++;

              }

              //***********************

             

             

              //mail($to,$subject,$body,$headers);

              //echo "<P>$message</P>";

              $i++;


Not sure i am any help or confusing the matter, you let me know.
-ALF


From: [hidden email] <[hidden email]> on behalf of certified <[hidden email]>
Sent: Tuesday, October 10, 2017 3:23 PM
To: [hidden email]
Subject: Sending with Multiple Domain Suffixes from Single Apache Server Box
 
How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain")

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
   [hidden email] sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
   [hidden email] sending from  /var/www/html/another needs mail sent from
[hidden email]
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Note that I don't want to receive email on my MX.






--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Wietse Venema
In reply to this post by certified
certified:

> How do I configure postfix to append the correct domain on outgoing emails
> from php on apache:
>
> I have LAMP on Centos 7 and a static IP. There are several domain names
> registered to that static IP:
> first.com -> my static ip
> another.com -> my static ip
> third.com -> my static ip
> My postfix MX server is also on the webserver box.
>
> php uses the following format:
> $result = mail($to, $subject, $message, $headers, "-f returndomain")

That is incorrect. The correct syntax is:

    $result = mail($to, $subject, $message, $headers, "-f address")

where the address is in user@domain form.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Bill Shirley
In reply to this post by certified
I let PHPMailer do the heavy lifting:
      $email_addresses = array(
        'first.com'=>'[hidden email]'
        ,'another.com'=>'[hidden email]'
      );
      if (is_set($email_addresses[$returndomain])) $from_address = $email_addresses[$returndomain];
      else die("returndomain=$returndomain not in array");

      require_once(PHPMailer);

      $mail = new PHPMailer();
      $mail->IsMail();
      $mail->IsHTML(true);
      $mail->SetFrom($from_address);
      $mail->AddAddress($to_address, $to_name);
      $mail->Subject = "Order $order_item was rescheduled";
      $mail->Body = $html_body;
      $mail->AltBody = "Order $order_item was rescheduled.\n\n$body_2nd_line";
      $mail->Send();
$to_name is something like 'Mike Smith'. Leave it out if you don't have it.

HTH,
Bill

On 10/10/2017 3:23 PM, certified wrote:
How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain") 

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
   [hidden email] sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
   [hidden email] sending from  /var/www/html/another needs mail sent from
[hidden email]
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual [hidden email] from addy
if returndomain is another.com, I would like postfix to send it with the
virtual [hidden email] from addy

Note that I don't want to receive email on my MX.






--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html

Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

certified
In reply to this post by certified
Actually I don't know the postfix main and master config file edits required
to send outgoing mail. The default ones seem to be only local?

BTW Thanks Bill for the php script. Are you saying that will work with
default config files? Will definitely use something like that one the config
files are OK.  



--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Wietse Venema
certified:
> Actually I don't know the postfix main and master config file edits required
> to send outgoing mail. The default ones seem to be only local?
>
> BTW Thanks Bill for the php script. Are you saying that will work with
> default config files? Will definitely use something like that one the config
> files are OK.  

There is nothing about Postfix that needs editing. You just need to
set up PHP to supply the correct sender address.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Bill Shirley
If your outbound mail isn't working, you should post the output of
postconf -n
so someone can help you.

Bill


On 10/11/2017 1:59 PM, Wietse Venema wrote:
certified:
Actually I don't know the postfix main and master config file edits required
to send outgoing mail. The default ones seem to be only local? 

BTW Thanks Bill for the php script. Are you saying that will work with
default config files? Will definitely use something like that one the config
files are OK.  
There is nothing about Postfix that needs editing. You just need to
set up PHP to supply the correct sender address.

	Wietse

Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

certified
>There is nothing about Postfix that needs editing. You just need to
>set up PHP to supply the correct sender address.

OK did some experimenting, sending to a very sophisticated email service:

Used the php command:
$result = mail($to, $subject, $message, $headers, "-f address")

With the generic posftix master and main files.
I got greylisted for 300 seconds ( http://greylisting.org )
postfix retried after 300 seconds and I got rejected because the sender was
myhost.localdomain, neither of which resolve on the internet.

So I changed the main.cf file as follows:
myhostname = www.first.com
mydomain = first.com
myorigin = $mydomain

That worked after getting greylisted again and postfix retried in 300
seconds.
There are some issues however:
I can't set another domain. If I send email from second.com the header file
on the recipient reads:
Return-Path: [hidden email]

Here are the values:
$to = "[hidden email]";
$subject = "test message";
$message = "some message";
$headers = "From: [hidden email]";

$result = mail($to, $subject, $message, $headers, "-f second.com") ;

On the second try, I don't get greylisted.

$result always seems to be 1 regardless









Bill Shirley wrote

> If your outbound mail isn't working, you should post the output of
> postconf -n
> so someone can help you.
>
> Bill
>
>
> On 10/11/2017 1:59 PM, Wietse Venema wrote:
>> certified:
>>> Actually I don't know the postfix main and master config file edits
>>> required
>>> to send outgoing mail. The default ones seem to be only local?
>>>
>>> BTW Thanks Bill for the php script. Are you saying that will work with
>>> default config files? Will definitely use something like that one the
>>> config
>>> files are OK.
>> There is nothing about Postfix that needs editing. You just need to
>> set up PHP to supply the correct sender address.
>>
>> Wietse


Bill Shirley wrote

> If your outbound mail isn't working, you should post the output of
> postconf -n
> so someone can help you.
>
> Bill
>
>
> On 10/11/2017 1:59 PM, Wietse Venema wrote:
>> certified:
>>> Actually I don't know the postfix main and master config file edits
>>> required
>>> to send outgoing mail. The default ones seem to be only local?
>>>
>>> BTW Thanks Bill for the php script. Are you saying that will work with
>>> default config files? Will definitely use something like that one the
>>> config
>>> files are OK.
>> There is nothing about Postfix that needs editing. You just need to
>> set up PHP to supply the correct sender address.
>>
>> Wietse





--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Bill Shirley
You're not using an address.  man sendmail:
-f sender
    Set the envelope sender address. This is the address where delivery problems are sent to. With Postfix versions before 2.1, the Errors-To:  message  header
    overrides the error return address.

It should be:
$result = mail($to, $subject, $message, $headers, "-f [hidden email]")
Bill

On 10/11/2017 4:02 PM, certified wrote:
There is nothing about Postfix that needs editing. You just need to
set up PHP to supply the correct sender address. 
OK did some experimenting, sending to a very sophisticated email service:

Used the php command:
$result = mail($to, $subject, $message, $headers, "-f address") 

With the generic posftix master and main files. 
I got greylisted for 300 seconds ( http://greylisting.org )
postfix retried after 300 seconds and I got rejected because the sender was
myhost.localdomain, neither of which resolve on the internet.

So I changed the main.cf file as follows:
myhostname = www.first.com
mydomain = first.com
myorigin = $mydomain

That worked after getting greylisted again and postfix retried in 300
seconds.
There are some issues however:
I can't set another domain. If I send email from second.com the header file
on the recipient reads:
Return-Path: [hidden email]

Here are the values:
$to = [hidden email];
$subject = "test message";
$message = "some message";
$headers = "From: [hidden email]";

$result = mail($to, $subject, $message, $headers, "-f second.com") ;

On the second try, I don't get greylisted.

$result always seems to be 1 regardless









Bill Shirley wrote
If your outbound mail isn't working, you should post the output of
postconf -n
so someone can help you.

Bill


On 10/11/2017 1:59 PM, Wietse Venema wrote:
certified:
Actually I don't know the postfix main and master config file edits
required
to send outgoing mail. The default ones seem to be only local?

BTW Thanks Bill for the php script. Are you saying that will work with
default config files? Will definitely use something like that one the
config
files are OK.
There is nothing about Postfix that needs editing. You just need to
set up PHP to supply the correct sender address.

	Wietse

Bill Shirley wrote
If your outbound mail isn't working, you should post the output of
postconf -n
so someone can help you.

Bill


On 10/11/2017 1:59 PM, Wietse Venema wrote:
certified:
Actually I don't know the postfix main and master config file edits
required
to send outgoing mail. The default ones seem to be only local?

BTW Thanks Bill for the php script. Are you saying that will work with
default config files? Will definitely use something like that one the
config
files are OK.
There is nothing about Postfix that needs editing. You just need to
set up PHP to supply the correct sender address.

	Wietse




--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html

Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Wietse Venema
In reply to this post by certified
certified:
> >There is nothing about Postfix that needs editing. You just need to
> >set up PHP to supply the correct sender address.
>
> OK did some experimenting, sending to a very sophisticated email service:
>
> Used the php command:
> $result = mail($to, $subject, $message, $headers, "-f address")

I told you to specify an email address (user@domain) form for 'address'.
That was on the line immediately after the above example.

> $result = mail($to, $subject, $message, $headers, "-f second.com") ;

But you failed to do what I told you.

I'm sorry, but email systems work only when you are precise.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

certified
> But you failed to do what I told you.

Yup, garbage in, garbage out.

OK, so I reworked the php and voila, the sender is now [hidden email]
or [hidden email]

However:
Using the default main.cf I get
Return-Path: [hidden email]
(The reply to works fine, though still getting response = 1)
But
Received: from myhost.localdomain (unknown [nnn.nnn.nnn.nnn] where nnn is my
ip

So I went back to using
mydomain = first.com
The reply to works fine but
gives: Received: from www.first.com (unknown [nnn.nnn.nnn.nnn]) regardless
if sent by first or second.

Maybe that is something I have to live with?





--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

Wietse Venema
certified:
> gives: Received: from www.first.com (unknown [nnn.nnn.nnn.nnn]) regardless
> if sent by first or second.

The RECEIVED line contains Postfix myhostname value, not the email
address. And you should have proper DNS so that www.first.com
resolves to the IP address, and the IP address resolves to
www.first.com. This is often part of a spam check.

The "-f [hidden email]" specifies among others the Return-Path
address, as well as the from= address in Postfix logs. This is also
the address in the MAIL FROM command in the SMTP protocol, which
is what remote hosts use for early spam blocks.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Sending with Multiple Domain Suffixes from Single Apache Server Box

certified
Appreciate all the help.

>you should have proper DNS so that www.first.com
>resolves to the IP address,

Have that, but I have three domains pointing to that IP from and1.com
So I guess there is nothing that can be done to get rid of
Received: from myhost.localdomain or first.com if I send it from second.com.
I guess the reply to will have to do.



--
Sent from: http://postfix.1071664.n5.nabble.com/Postfix-Users-f2.html