You need to use headers. This worked for me:
$to = "mail@example.com";
$subject = "your subject";
$body = "<p>Your Body</p>";
$headers = "From: Sender Name <mail2@example.com>" . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $body, $headers);
Additionally you can add a TXT Record
for SPF
in your Registrar where you got your domain. Go to the DNS Settings and add the following TXT Record:
Type: TXT
Host: example.com
Value: v=spf1 ip4:YOUR.SERVER.IP.HERE ~all
TTL: Automatic
This is for validating that the mail hasn't been spoofed.