Forum Moderators: coopster

Message Too Old, No Replies

PHP mail form

looking for coding help

         

zebraplayer

1:08 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



hello all,

I am less than a newbie when it comes to PHP. I recently picked up a book and I am trying to get through. So please keep that in mind when you post a reply.

I have a mail form that is working great except that when it sends me the e-mails, it does not want to put the sender's e-mail address in the "From" field of the e-mail. The book that I have simply says that there is not a foolproof way to fix this. I say, that is why I bought the book, but it still doesn't explain it.

If you know a workaround for this little issue I would appreciate your help. I tried searching this site for a similar post, but I am must not be typing the right question, 'cause I ain't finding an answer.

Thanks in advance for you help.

-LG

mincklerstraat

1:34 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of the users' comments in on the mail() function at php.net suggests using ini_set() to set the reply address (this is sort of like setting it at the server level, but only for as long as the page executes).

ini_set("sendmail_from", "replyadress@domain.com");
Set this in your formmail script near the top.

from: [be2.php.net...]

Congrats on springing for the php book; this helps alot in getting the programming stuff into your head (and a lot of newbies don't do this). Hope it's a relatively new one. Still, make a habit of checking out the manual over at php.net. Get the firefox browser, and in the right-hand searchbox on top, if there isn't a drop-down option for 'add engines', then look for an extension called 'mycroft' and add the php functions lookup option. Just type in a function name, and bang, you're there. Users' comments are really helpful too. This is the best way to learn how to use the functions well; having the paper book will help too, since you can go over real life examples in a more restful environment.

And welcome to webmasterworld.

Zipper

2:48 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



it's probably with the wrong variable assigned for the sender's address. could u post a snippet of your code?

zebraplayer

3:07 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



This is the line of code that I have. As it stands now, it sends me the e-mail address typed by the user, but it places it above the body text, not in the "From" field of the e-mail.

<?
mail('info@MYDOMAIN.com', $_POST['subject'], $_POST['body'], $_POST['emailAddress']);
?>

If someone could give the exact way to correct the problem, I would appreciate it.

Timotheos

3:29 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you need it like this...

mail('info@MYDOMAIN.com', $_POST['subject'], $_POST['body'], "From: " .$_POST['emailAddress']);

Typically I've done it with the name as well
mail('info@MYDOMAIN.com', $_POST['subject'], $_POST['body'], "From: " . $_POST['first_name'] . " " . $POST['last_name'] . " <" . $_POST['emailAddress'] . ">");

Zipper

3:40 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



there u go. that would do it.

zebraplayer

4:10 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



That was so frigging simple. Why couldn't the book say that? What's so not "foolproof" about that?

Anyway, thanks again for all your help.

You guys rock!

-LG

Timotheos

5:42 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sweeet.

The book might be talking about the Return-Path part of the header which I haven't figured out how to override on a shared server. The php mails I send still have the notorious 'nobody' as the return path.

You'll want to get your head around the header part of the mail function (was that a pun?). The manual [php.net] has some examples and links to the relevant RFCs.

Tim