...

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



loonatik
03-18-2003, 10: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?

thanks.

Nightfire
03-18-2003, 11:03 PM
$to = 'their@emailaddress.com';
$subject ='Your subject';
$body = 'Your message';
$header = 'Your email address <you@yourdomain.com>';

mail($to,$subject,$body,$header);


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;
}
}

}

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


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

<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>');
//-->
</script>


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

loonatik
03-19-2003, 05: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.

Thanks.

Nightfire
03-19-2003, 05:06 PM
$REMOTE_ADDR

[m]
03-20-2003, 06: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

bored
03-20-2003, 06: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.

Nightfire
03-20-2003, 06: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>

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

Yes.

Yog?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum