This is a discussion on "When a form is sent as email, how do I get an address in the from heading?" within the PHP Forum section. This forum, and the thread "When a form is sent as email, how do I get an address in the from heading? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
When a form is sent as email, how do I get an address in the from heading?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
When a form is sent as email, how do I get an address in the from heading?
Hi I've successfully put a form into my site but when I receive the emails, it has a blank in the "from:" section. Check my code below that the php file sends to my email. I put in that "headers" and "from" title in, not knowing much about php yet, but it doesnt seem to do anything. How can I get the email I receive to have a "from" (even if its from the same address as the one receiving it?
Also, my customers can send a message concerning either "information" or "website problems" I have a little options bar for this, which you can see at: http://www.bernisnudelbrett.de/en/contact.html How can I get the php code to send to different emails, depending on the topic chosen in "concerning"? Would I need to add to the form code in the contact.html page or to the code in the contact.php page (where I understand, the information is processed and sent on. Anyway look at the code below and let me know if you can answer either problem! Thanks This is the code on "contact.php"
|
|
|
|
#2
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
With regard to sending to a different email address, you can tackle this in your contact.php file.
mail($mailto, $mailsubj, $mailbody, 'From: ...'); NOTE: You only need the four variable, not the five that you have. If you need to have a complex mail header, then build the header seperately and insert it in place of the 'From: ...'. |
|
#3
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Hi thanks for the code
I tried putting it in but it wouldnt work. I deleted the original 'mail to' and changed as suggested On net it says there ¡s a parsing error.
|
|
#4
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Yes. 1st. You are collecting the value of $email when you should be collecting the value of $emailfield. 2nd. Dont use $HTTP_POST_VARS anymore. Use $_POST 3rd. The field name inside the [] needs to be in quotes. 4th. Where you set the value of $mailhead, you have included the value of the collected variable as part of the string instead of appending its content. Assuming you correct the first three what you want is: $mailhead = "From: ".$emailfield; Note also that the new line, \n is not required for a simple header like this. |
|
#5
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Hi Geoff
Thanks for your assistance, I'm a PHP for Dummies level user at the mo, so bear with me! I've changed the code as you suggested but am getting the following error in my browser: Quote:
By the way, when you say Quote:
|
|
#6
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
You don't surround php code with the <script>...</script> tags, php is surrounded by; <?php...?> You are trying to pick up a value from a field named 'email'. In you form code, the email field is called 'emailfield'. I've pointed this out to you previously. The third line above should be; $concern = $_POST['concerning'] Quote:
Get rid of these bits of code:
Although I've told you to get rid of the above, note in your code that on two of the above lines you have ; followed by }. ; terminates a line of code in php and accounts for your error message. Do you have any php reference to hand at all? Last edited by ukgeoff; Jun 4th, 2006 at 18:07. |
|
#7
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Hey, just been out of town for a day. Yes, I have PHP for Dummies and Ive just started reading it, so hopefully this lack of knowledge will dissapear over the coming weeks as I play around. For this reason, it's difficult at the moment to understand the basic PHP concepts as I'm not used to the vocabulary used yet. I'll correct the coding as you suggested. Thanks
|
|
#8
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
HI Geoff
Its quite poissible you're banging your head against a table in despair at my idiocy, but I've tried to make your amendments as suggested and its not accepting that '}' symbol as shown when the message is sent from contact.html to contact.php... It relates to the one on the 'if' line that you gave me. Quote:
Quote:
|
|
#9
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
With the exception of the drop down menu this thread concerns forms too: http://www.webforumz.com/html-forum/...m-problems.htm
Although keep in mind that making one will help you learn (as you are) but will be more frustrating (as you can see).
Last Blog Entry: Whats in a name? (Feb 20th, 2008)
|
|
#10
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
The code below is at least syntactically correct. Try it and see what you get.
The single '=' sets left equal to right. The double '==' is a comparison. Does left equal right. It often catches people in the early days. |
|
#11
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
<off topic>
@ukgeoff - as a designer somethings in development can be confusing so I was extactic when I could easily understand the difference between = and ==. Everything I have seen about it now makes sense. Thank You. </off topic>
Last Blog Entry: Whats in a name? (Feb 20th, 2008)
|
|
#12
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Nice one guys
I shall try the new code, after a week of reading php and mysql for dummies, I'm wondering if there's a grade lower than dummy! Will let you know how it works out. |
|
#13
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Resolution (kind of)
OK, put the code in today and tried it. All works fine and starting to understand it, except, I was only getting "message from a website visitor" in the message body of the email, so I copied that bit of code that I'd found on the net originally and used that instead, now I get all the info from the original form. so instead of your line Quote:
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; } if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); } ?> Even thought you said I didnt need that line, it seems to give me the results I want. The messages will now go to either the info email or web email and all the comments are included so I'm pleased with the result, but one thing I still don't get. When I test run a few emails to each address, not all of them come through. If I send 4 or 5 in succession, they should all be processed, right? I don't think the problem is that code I changed from your suggested line, because the same thing happens whichever code I use. Any suggestions? |
|
#14
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
The reason for the mesage you were seeing in the body is because if you look at the code i gave, you which is your code with my corrections, that message is hard coded into the code, i presume for test purposes.
You need to pick up the actual message using:
Are you still having problems sending multiple emails? |
|
#15
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
Multiple emails no prob now and I have just got an addition off someone else to what you have shown me below
$mailbody = $_POST['title'] . "\n"; $mailbody .= $_POST['namefield'] . "\n"; $mailbody .= $_POST['concerning'] . "\n"; $mailbody .= $_POST['comments']; this way I have everything I need in the message. What exactly does \n mean? Only nagging problem now is that not all of the emails are coming through and I wonder if it is a problem with the spam filter of the hosting company. Thanks geoff |
|
#16
|
|||
|
|||
|
Re: When a form is sent as email, how do I get an address in the from heading?
It adds a new line character so the each fields content when printed start on a new line.
|