April 7, 200818 yr Hey, I was given a standard php contact form, and as ive been learning ive been trying to customise for my needs. Now, what i want to do is change the headers (so for example, instead of saying from Apache, it says from the Sales Team) on the email that the mail function sends. I read a tutortial on it, but im getting errors when im testing it out. Id really appreciate it if you could have a look over it. <!--Contact Form Code Start--><?php fixed now <!--Contact Form Code End--> Thanks for any help
April 7, 200818 yr It's because you're using unescaped quotes. $body (line 59) and $their_body (line 66) both are double quoted strings where you have unescaped double quotes inside. When you use large chunks of text like that I'd suggest you use a heredoc string. http://no.php.net/types.string#language.ty....syntax.heredoc By the way? What editor do you use? Plain text notepad? When I viewed the code in PHP Edit which colours the code I spotted the problem right away. PHPEdit also immediately highlighted the syntax error for me.
April 7, 200818 yr Author It's because you're using unescaped quotes. $body (line 59) and $their_body (line 66) both are double quoted strings where you have unescaped double quotes inside. When you use large chunks of text like that I'd suggest you use a heredoc string. http://no.php.net/types.string#language.ty....syntax.heredoc By the way? What editor do you use? Plain text notepad? When I viewed the code in PHP Edit which colours the code I spotted the problem right away. PHPEdit also immediately highlighted the syntax error for me. Thanks a lot for the reply. I got it now. I was just using notepad, but ive downloade Notepad++ and find it much easier now. I would like to know why the code below works though. Is it becuase it is a single quote mark, so you dont have to escape the double quote marks of the "center"? In that case wouldnt it be easier to always use since quote marks? Or do you have to use single some times, and double others?
April 7, 200818 yr I would like to know why the code below works though. Is it becuase it is a single quote mark, so you dont have to escape the double quote marks of the "center"? In that case wouldnt it be easier to always use since quote marks? Or do you have to use single some times, and double others? Exactly, you don't need to escape the double quotes when the string is inside single quotes. Apparently single quotes are faster for simple strings. Don't know how true that is. Somebody please put me right. Also your form layout isn't displaying correct in Firefox.
April 7, 200818 yr Forget that last comment, it seems to be displaying ok now. Did you change it or am I seeing things?
April 7, 200818 yr Author OK, i think ill stick to single quotes then - much less hassle! But im sure theres a reason why people use double quotes, i mean why go through all the hassle of escaping when you could just use single quotes, unless theres a reason im not seeing. Yeah, im having troubles with the menu bar. Im assuming your running Firefox 2?
April 7, 200818 yr Exactly, you don't need to escape the double quotes when the string is inside single quotes.Apparently single quotes are faster for simple strings. Don't know how true that is. Somebody please put me right. Also your form layout isn't displaying correct in Firefox. Single quoted strings are literal strings. The only special characters is the \' to escape single quotes. Double quoted strings let you put variables inside it and add characters like \n \t etc to represent linebreaks and tabs. Due to this they are slightly slower. Heredocs works the same, except that it spans over multiple lines. So unless you use variables or special characters, use single quoted strings.
April 7, 200818 yr Just a quick example: var $var = 'world'; var $foo = "Hello $var \n This is second line"; This will outout Hello worldThis is second line var $var = 'world'; var $foo = 'Hello $var \n This is second line'; This will outout Hello $var \n This is second line As you can see, single and double quoted strings got different purposes.
April 11, 200818 yr Author Sorry for the slow reply. That example really makes things clear - thanks. All is working well now. Cheers.
Create an account or sign in to comment