Page 1 of 1

Stumped with Simple Form Code

Posted: Sun Oct 28, 2007 5:24 pm
by awieds
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

Although I have coded in ASP, I have not really done anything in PHP. Recently I redid my company website. There were a couple of pages that were PHP. Instead of going through it I just changed the HTML so that it fit in with the rest of the site. Recently we switched to a new host and moved all our files. The PHP page is no longer functioning properly. This is the problem.
User is on an HTML page with a form. He fills out the form and the information is supposed to be sent in an email (via GET) and he is redirected to a new page. Now all that works fine except that all the variables in the email are blank. It goes to the right email address, and the date is correct as well as all the text, like Name: Last Name: etc. but the variables are just blank. Now when going from one page to the next, all the variables are displayed in the web address, so the problem is not in the HTML form page, but rather the variables are for some reason not being picked up.
Now, like I said, I am not familiar with PHP. So I researched a bit online and notices the variables were not being grabbed properly. So I changed to code to $_GET[first_name]; etc. But when I did this, although the variables still showed up in the address, the page being redirected to was blank and the email not sent.
I am really confused. What could have gone wrong in changing it from one host to the next? The following is the PHP code:

Code: Select all

<?php
function doError($errString) {

    include($header);

    echo "$errString<BR><BR>\n";

    include($footer);

    exit;}

$today = date ("F j, Y g:i:s a");
$strMessageBody = "";
$strMessageBody .= "New Download Request:\n";
$strMessageBody .= "\n";
$strMessageBody .= "Registration Date: $today \n";
$strMessageBody .= " \n";
$strMessageBody .= "Information: \n";
$strMessageBody .= "-------- \n";
$strMessageBody .= "   $ntitle $firstname $surname \n";
$strMessageBody .= "   Company: $company \n";
$strMessageBody .= "   Job Title:$jobtitle \n";
$strMessageBody .= "   Phone: $phone \n";
$strMessageBody .= "   eMail: $email \n";
$strMessageBody .= " \n";

$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$myname."\" ".$myemail."\n";

//# Send email order to you...
$mailheaders = "From: info@whatever.com\r\n";
$mailheaders .="X-Mailer: PHP Mail generated by http://www.Whatever.com\r\n";
$subject = "New Lead for Whatever";
//echo "sending email";
mail($mail, $subject, $strMessageBody, $headers);
//echo $email;
$fd = popen("/usr/sbin/sendmail -t -f john@whatever.com","w");
fputs($fd, "To: mary@whatever.com \n");
fputs($fd, "From: info@whatever.com \n");
fputs($fd, "Subject: Whatever\n");
fputs($fd, "X-Mailer: PHP3\n");
fputs($fd, "$strMessageBody\n");
pclose($fd);

?>
Thanks in advance,
awieds


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Oct 28, 2007 5:53 pm
by califdon
I understand your problem. I've had to try to go the other way, from PHP to ASP. Frustrating!

First of all, if that's the entire script, you're missing all the parts that declare and populate the variables (in PHP, all variables begin with $ ).

You need something like the following:

Code: Select all

$ntitle = $_GET['ntitle'];
$firstname = $_GET['firstname'];
$surname = $_GET['surname'];
$company = $_GET['company'];
  ...  etc.
at the beginning of your PHP code. Of course, the variable names inside the square brackets must match the keys in the URL, so you need to check the code that is generating the URL (or observe it in the web address).

That said, it is a security issue to use these variables without validating each one, since anyone else can see how to make your script send an email to somebody, so you should add some validation code before sending your email.

It also appears that you are sending the same email by two different means. I would expect the recipient to receive two identical copies. The single line

Code: Select all

mail($mail, $subject, $strMessageBody, $headers);
should do the job; the 7 lines below that, beginning with $fd =, are just duplicating the operation.

Also, unless it is called from somewhere else, the function doError() isn't being used, so you could just as well eliminate it.

In case you have excerpted this from a more complete script, some of my comments won't be applicable.

THANK YOU!

Posted: Mon Oct 29, 2007 4:56 am
by awieds
Thank you so much. I really appreciate your help. Once I declared the variables as you suggested it worked.