All public web servers expose their public IP addresses. The only IP that is hidden from public access is the private network IP. Anyone could get the IP of a web server by performing a DNS lookup. That said, there’s no need to worry about public IP exposure – properly setting up your firewall will mitigate most common concerns regarding public exposure.
Beyond the firewall, further locking down the droplet and tightening security will further prevent the majority of other cases.
Sending Mail w/ PHP
As far as sending e-mail using PHP, the
mail() function really doesn’t accept connection parameters on the fly so you wouldn’t be connecting to your mail server using this function.
The following lines of code should send an e-mail without any issues:
$headers = 'From: firstname.lastname@example.org' . "\r\n" .
'Reply-To: email@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
* 1). E-Mail Recipient
* 2). E-Mail Subject
* 3). E-Mail Message
* 4). E-Mail Headers
'Testing An E-Mail Using PHP 7',
'This is a test message using PHP 7.x to send.',
… of course, since you’re not connecting to your mail server, this e-mail will most likely end up in the SPAM box of whatever provider it’s being sent to since there’s absolutely zero authentication using the above.
If you want something more advanced, such as actually sending through your mail server, I’d recommend using something such as PHPMailer:
These libraries provide a feature-rich set of functions that’ll allow you to do what you need to do and connect to your mail server by passing the correct details during configuration.
If you’re using a CMS, such as WordPress, you can use a plugin to handle the connection for you. You can take a look at: