PHP and PowerMTA - php

I have installed a server mail in a dedicated server and I have PowerMTA installed also, our server has a main IP address and 50 additional ones,Multiple VMTA are configured. Now I need to send email with php through PowerMTA and be able to choose each time a different IP. I know I have to use PHPMailer or another library but I do not have any idea on how to send emails via PowerMTA and choose the IP or the vmta (contain the IP and the domain) to use.
Any help would be much appreciated
Thank you

You will need to refer to the PowerMTA documentation for this, which is not officially available online (see chapter 8).
You select a specific virtual MTA in PowerMTA by setting a custom message header called x-virtual-mta when you submit messages to the MTA, which is done using addCustomHeader in PHPMailer, passing whatever name you need to use for your VMTA:
$mail->addCustomHeader('x-virtual-mta', 'my-vmta-name');
You need to ensure that your source IP is permitted to select VMTAs via this method in your PowerMTA config, for example:
<source 127.0.0.1>
process-x-virtual-mta yes # allow selection of a VirtualMTA
always-allow-relaying yes # allow feeding from 127.0.0.1
</source>
I would avoid embedding IP addresses in your code; stick to using VMTA names.

Related

How to find server domain name for SMTP from PHP?

I have cPanel servers which run the same script, but I've hard coded the server name in to the code as I can't find anywhere to grab the actual server domain.
Imagine 3 cPanel servers and these are the server domains:
apple.hosting.com
banana.hosting.com
carrot.hosting.com
While running a PHP script to send mail via SMTP, I need to connect to the server and want to use the server name that would be provided for secure connections.
I don't want to create an array of the IP addresses and then have it compare, as that won't work with dedicated IP addresses.
I tried ini_get('SMTP'), which just returns a useless 'localhost'.
I tried ini_get_all(null,false), and no joy.
I checked the $_SERVER global, but only the domain being accessed appeared.
The only thing that returned the server name was phpinfo().
It took a while to find this, and in composing the question, I found the answer. Rather than waste what I think is a good question (since I couldn't find the answer easily), here it is:
New as of PHP 5.3:
gethostname();
That's it, nice and sweet.
Read more here: PHP function gethostname
You could send yourself an email an look in the email header (In Outlook: Open the mail, View->Options, there is 'Internet headers)
The normal sub-domain is mail.domain.com, and another solution could be:
Follow this:
cpanel --> go to your mailing accounts -- > click on configure mail account -- > there somewhere in the page you will get the information about your smtp server
And on that page you should find the information.
Have a look at mxtoolbox
Other then that, you'll probably want to check stream-socket-client

Sending mail from webserver to external mail server with local domain name

This is an issue I've encountered several time and haven't yet found a decent solution for:
Sending an e-mail from a webserver on e.g. "domain.com", to info#domain.com which is hosted on an external mail server e.g. Google Mail
In my case I always send from PHP over Apache and often on shared hosting, but I can imagine this is the same case on other frameworks.
These e-mails always seem to be delivered to the local mail server, even if I set the MX records on that server to point to the right external mail server.
A solution for this is to use an external SMTP server, but this isn't always easy when you're working with clients that either need to set-up a new e-mail account on their server and provide the SMTP details or sign-up for a third-party SMTP server.
What is the solution for this? Is there no way around SMTP?
Most emai/MTA server "autoconfigure" themselves. They guess list of local email domains (doimans with locally hosted mailboxes).
In sendmail case you can turn it off adding the following line in sendmail.mc:
define(`confDONT_PROBE_INTERFACES', `True')
Documentation : cf/README - confDONT_PROBE_INTERFACES
I have had the same issue many many times (in my case using PHP on a LAMP stack).
Try/check the following.
If you are using cPanel or similar, set the MX records to the external mailserver (Google apps etc).
Set up an SPF record to allow your hosting website to send email (this way no need to configure SMTP).
This may not be applicable but if you are using something like phpmailer. Set the property $mail->isMail(); so it tries to use your SPF allowed local mail() function to send the email. Sorry for going off into very specific advice, but might help in your particular situation.
Worth checking there are not similarly named local mailboxes on your hosting box.
Hope this helps!

Virtual Hosts / Postfix mail log, show sending website

I've been googling around for awhile now and have been unable to find any sort of solution or any information at all.
What I need to do is to configure postfix so that when one of our websites sends mail using PHP (via a contact us form or w/e) the mail log will show what the sending website was. This way we can identify a compromised website/form, etc in case one of our IP addresses should get blacklisted. We run virtual hosts so each server could have dozens to hundreds of websites on them. For us to otherwise track them down manually could take forever.
Is this even possible? Perhaps its not if I couldn't find anything on google :(
Consider using PHP 5.3's new mail.log configuration directive. It will allow you to define a log file where all calls to the mail() function are recorded, including the To address, the headers, and the full path to the script that made the call.
If you aren't running 5.3, consider upgrading to it, or to 5.4 once it's out in a few weeks.
Unfortunately this is only half of a solution. There are numerous PHP mail libraries that speak SMTP. If you permit local SMTP connections (as most good web hosting providers should), then users would have a way to bypass that log.

Change HELO host name when sending email

A customer's website address is customerswebpage.com (not the real one, of course). The server itself has it's host name configured to server.customerswebpage.com, which has no A or MX type DNS records. This causes many web servers to refuse mail from this server.
Is there an easy and/or neat way to change the HELO address the server identifies itself as? The site is built on the Symfony framework version 1.0 and we're using the sfMail plugin to send the mail. The only solution I could think of so far is taking a copy of the whole plugin and modifying it to suit our needs, as the hostname is used only internally.
Maybe even more importantly, do you think we could say this is a DNS misconfiguration?
I think HELO needs to be changed in server's MTA and not in php.
http://www.sendmail.org/m4/whoami.html
You should probably just add the missing A and MX DNS records for server.customerswebpage.com and not change HELO.
Mail servers can be really picky, and it is by no means granted that adding a proper A and PTR record for the server will resolve all issues. It is usually most hassle-free to use an external smarthost (for example via your ISP or a dedicated service) for outgoing mail, and let them worry about deliveries.
The sfMail package is based on PHPMailer, and that package stores the HELO host name in $helo. Perhaps you can overload the sfMail phpMailer class and set that variable?
A way for avoiding this problem is to use sfMail with SMTP. So you can send your E-Mail with your real Mailserver so the SPF and MX Records are right.

How to send email from a specific ip address?

I'm running a vps with cPanel/CentOS, And i want to dynamically choose the IP address to send an email from right inside the php code. ( i'm open to any weired ways )
Is there any way to do that? i would really appreciate some clear ideas as i'm not that good at exim and stuffs.
P.S. i already have available IPs in WHM.
Thank you
You can achieve this by using sendmail and passing parameters to define the configuration file to use. Inside the configuration file you can use the Masquerading And Relaying options together with CLIENT_OPTIONS(`Addr=aaa.bbb.ccc.ddd') to send via a certain IP.
When using PHP mail use the additional_parameters to specify the sendmail config file to use and in that config file use the above options to configure it.
PHP has no control whatsoever over the SMTP server that sends the mail. You can bind SMTP servers (sendmail, postfix, exim, etc...) to specific interfaces, but that's got nothing to do with PHP. PHP's involvement with the email sending process is purely to generate the mail and then hand it over to an SMTP server for actual delivery.
Here is a thought. If what you need is to send the mail from a specific IP you have control over, but where the impetus for that mail doesn't originate from that IP, but from some web interface or whatever, you could:
Add the mail details to a table on a DB with the desired IP address as a field.
Setup crons to run a php script on each box with those IPs.
Parse over the table with that script to find any mail that needs to come from that IP.
Send the mail.
I have a reseller account on a virtual host and all my domains for example are under the same IP number, then whatever domain I'm using to send an email, it will be sent under the same IP number, I think it is controlled by the smtp especification, you can configure your smtp to send email with another server where of course you have an account.
Also create a table to control what server you want to use to delivery yours email.
ClientPortOptions and DaemonPortOptions are special cases since multiple
clients/daemons can be defined. This can be done via
CLIENT_OPTIONS(`field1=value1,field2=value2,...')
DAEMON_OPTIONS(`field1=value1,field2=value2,...')
Note that multiple CLIENT_OPTIONS() commands (and therefore multiple
ClientPortOptions settings) are allowed in order to give settings for each
protocol family (e.g., one for Family=inet and one for Family=inet6). A
restriction placed on one family only affects outgoing connections on that
particular family.
Source: http://www.sendmail.com/sm/open_source/docs/configuration_readme/

Categories