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 )
开发者_JAVA百科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/
精彩评论