PHP mail function 'from' address

email, php

Solution

See this page on the same site (example 2): http://www.w3schools.com/php/func_mail_mail.asp

You will have to set the headers of the message to include the From and other stuff like CC or BCC:

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com\r\n";

mail($to,$subject,$txt,$headers);
?>

Note that you have to separate the headers with a newline sequence `"\r\n"`.

Problem

I'm not even sure this is possible, however what I'm trying to do is as follows. I have an HTML form that generates and email using a `PHP` script. What I want is to recieve emails from this form to `abc@xyz.com`, then I want the `from` address to appear as one of the fields in the form. I have had a look around and found some useful information on this site. I'm not sure whether `sendmail_from` can be used in this situation, or if it does what I'm asking. Is this possible, if so how?

Original source