How to send email from a specific ip address?

我只是一个虾纸丫 提交于 2019-11-30 15:58:20
Richard Harrison

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!