DevHeads.net

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 <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> 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:
<a href="mailto: ... at first dot com"> ... at first dot com</a> sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
<a href="mailto: ... at another dot com"> ... at another dot com</a> sending from /var/www/html/another needs mail sent from
<a href="mailto: ... at another dot com"> ... at another dot com</a>
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 <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

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

Comments

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Wietse Venema at 10/10/2017 - 16:17

That is incorrect. The correct syntax is:

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

where the address is in user@domain form.

Wietse

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Fazzina, Angelo at 10/10/2017 - 15:54

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 = " ... at uconn dot edu<mailto: ... at uconn dot edu>";

$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

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 <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> 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:
<a href="mailto: ... at first dot com"> ... at first dot com</a> sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
<a href="mailto: ... at another dot com"> ... at another dot com</a> sending from /var/www/html/another needs mail sent from
<a href="mailto: ... at another dot com"> ... at another dot com</a>
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 <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

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

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Fazzina, Angelo at 10/10/2017 - 16:03

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

check this out

<a href="http://www.postfix.org/ADDRESS_REWRITING_README.html" title="http://www.postfix.org/ADDRESS_REWRITING_README.html">http://www.postfix.org/ADDRESS_REWRITING_README.html</a>

This sounds like your idea :

Replace an internal address by an external address. For example, replace " ... at localdomain dot local" by "isp- ... at isp dot example" when sending mail from a home computer to the Internet.

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 = " ... at uconn dot edu<mailto: ... at uconn dot edu>";

$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

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 <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> 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:
<a href="mailto: ... at first dot com"> ... at first dot com</a> sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
<a href="mailto: ... at another dot com"> ... at another dot com</a> sending from /var/www/html/another needs mail sent from
<a href="mailto: ... at another dot com"> ... at another dot com</a>
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 <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

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