View Full Version : email/name in the "from" field?

03-18-2003, 11:46 PM
i hv a sign-up form, but when the contents are sent to me, the from field is always the server name of my webhost. is there a way to make it so that the email address or name of the person signing up appears as the from field in my inbox?

also, is there a way to check whether the email address entered has a '@' (for validity)? i tried using indexOf syntax, but not working.

oh, one more thing, i'm using an image as reset and submit buttons. the submit button works fine, but when i click on the reset button, it doesnt reset. instead, it just does what the submit button would do. i hv this:
<input type="image" value="cancel" src="images/reset.jpg">
is there something wrong?


03-19-2003, 12:03 AM
$to = 'their@emailaddress.com';
$subject ='Your subject';
$body = 'Your message';
$header = 'Your email address <you@yourdomain.com>';


this looks a decent email validation script (not checked, just glanced over), taken from http://php.net/eregi (http://www.php.net/manual/en/function.eregi.php)

// function to validate email
function validate_email($email_raw) {

// replace any ' ' and \n in the email
$email_nr = eregi_replace("\n", "", $email_raw);
$email = eregi_replace(" +", "", $email_nr);

// do the ergei to look for bad characters
if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*".
"@([a-z0-9]+([\.-][a-z0-9]+))*$",$email) ){
// okay not a good email
$feedback = "Error: $email isn't a valid mail address!";
return $feedback;
} else {
// okay now check the domain
// split the email at the @ and check what's left
$item = explode("@", $email);
$domain = $item["1"];
if( gethostbyname($domain) == $domain) {
$feedback = "Error: $domain isn't a valid domain!";
return $feedback;
} else {
$feedback = "valid";
return $feedback;


03-19-2003, 12:28 AM
For the button (nothing to do with php, but as it's mainly a php thread, I'll give you the answer)

<p><input type="reset" value="Clear"></p>

<script type="text/javascript">
document.write('<p><a onclick="document.theform.reset();return false;"',
'href="#"><img alt="Clear" src="clear.gif" border="0"><\/a><\/p>');

Plenty of ways to do it on here (http://www.cs.tut.fi/~jkorpela/forms/imagereset.html)

03-19-2003, 06:00 PM
everything works. thanks.

one more question - can i also have the ip address of the person signing up to be sent to me also? i think it's environment variables in cgi/perl, but not sure about php.


03-19-2003, 06:06 PM

03-20-2003, 07:04 AM
lol I was going to post a topic on how to validate emails but I lookd through the topics first... this might solv my problem..I'm glad I looked here

03-20-2003, 07:46 PM
Use e-mail headers for the mail function.

$headers = "From: $name <$email>\r\n";

By the way. On the 2nd post's example I dont think "Your email address" is a valid e-mail header.

03-20-2003, 07:50 PM
What's the difference from what I put and what you've put? :confused:

<edit> Ahh, yeah, forgot the From: bit, glad someone picked it up</edit>

03-20-2003, 09:40 PM
The From: explicit, and the ending carriage returns '\r\n'