Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help sending email w/ from form data

Status
Not open for further replies.

WintersTears

Technical User
Aug 6, 2008
6
US
Ok, I'm sorry if this is all going to sound silly and simple, but I'm completely lost and I lack simple brain functions. So I'm probably going to add a bunch of informaiton that is completely irrelevant too.

I have a form that is connected to my Access Database. There are 3 .asp pages and one .php page. Page 1.asp is where the user inputs their information; Page 2.asp pulls that info, checks that all require info is present and asks user to confirm; Page 3.asp pulls the info over again, displays who the email info (from, to, cc, subject) and asks to submit, and Page 4.php has the script to actually send the info.

The problem is that the last page, the php, is not pulling that information over so it can send an email. I think its basically saying "email nothing to nobody". (But, I'm probably wrong) Here is the code:
<?
//Send an Email

$mailheaders = "From: $MailFrom\n";
$mailheaders .= "Reply-To: $MailFrom\n\n";

echo $mailheaders;

$MailAddress = $MailAddress.$MailCC;

echo "<br>to:";
echo $MailAddress;

echo "<br>subject:";
echo $MailSubject;

echo "<br>body:";
echo $MailBody;

mail($MailAddress, $MailSubject, $MailBody, $mailheaders);

?>

Can somebody please get w/ me and see if you can help my poor brainless soul. Thank you!!
 
Is there any reason you are not using ASP to send the email?
You seem to use it for everything else.

Anyway, your code seems o.k the only question I have is where do your variables get their values from?

You know where are $MailFrom, $MailAddress, $MailSubject and $MailBody getting their contents?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Well, I didn't set this site up, I just got the task of trying to fix it. Apparently the person who set this all up has been gone for years upon years and nobody in our network knows anything about this.

If I knew how to set up anything, I would consider using .asp, but I haven't a clue.

The last asp page, where you hit Submit to go to the php page has this code w/ the submit button.
<form method="post" action="<input type="hidden" name="MailFrom" value="<%=strMailFrom%>">
<input type="hidden" name="MailAddress" value="<%=strMailAddress%>">
<input type="hidden" name="MailCC" value="<%=strMailCC%>">
<input type="hidden" name="MailSubject" value="<%=strMailSubject%>">
<input type="hidden" name="MailBody" value="<%=strMailBody%>">
<input type="submit" value="Submit">

It seems to me that this is where the data values should come from, but I just don't know how to connect it over.

I've also wondered if its possible to have that Submit button send off the email and link over to the next page that just says "Thank You" and gives info on who to contact if they don't receive the email. If that is easier, then I'm all ears.
 
Try using $_POST[] or $_REQUEST[] arrays. If a form is submitted, simply referring to the variable names is not going to work (unless you have GLOBALS ON ... I think).

If 3.asp form uses method POST, then use $_POST[]. If you are using method GET, then use $_GET[]. Using $_REQUEST[] is a safe bet as it will handle either methods.

So, change your code to look like this:
Code:
<?
//Send an Email

$mailheaders = "From: $_POST['MailFrom']\n";
$mailheaders .= "Reply-To: $_POST['MailFrom']\n\n";

echo $mailheaders;

$MailAddress = $_POST['MailAddress'].$_POST['MailCC'];

echo "<br>to:";
echo $MailAddress;

echo "<br>subject:";
echo $_POST['MailSubject'];

echo "<br>body:";
echo $_POST['MailBody'];

mail($MailAddress, $MailSubject, $MailBody, $mailheaders);

?>

I think these changes may help!
 
ahh that makes sense. It seems yo are relying on something called register_globals to be turned on. Which hasn't been the case for many versions of PHP now.


With it turned on, form elements would automagically be converted to variables by PHP. Since this was deemed dangerous the option was set to be turned off by default. And Should be kept off.


To access the form elements its a simple deal of using the correct global variable. Since your form uses the Post method the variable to use would be the $_POST variable.

Then its just a simple case of referring to the variables like so:

Code:
$mailheaders = "From: [red]$_POST['[/red]MailFrom[red]'][/red]\n";
$mailheaders .= "Reply-To: [red]$_POST['[/red]MailFrom[red]'][/red]\n\n";

echo $mailheaders;

$MailAddress = [red]$_POST['[/red]MailAddress[red]'][red].$_POST['[/red]MailCC'][/red];

echo "<br>to:";
echo $_POST['MailAddress'];

echo "<br>subject:";
echo [red]$_POST['[/red]MailSubject[red]'][/red];

echo "<br>body:";
echo [red]$_POST['[/red]MailBody[red]'][/red];

mail([red]$_POST['[/red]MailAddress[red]'][/red], [red]$_POST['[/red]MailSubject[red]'][/red], [red]$_POST['[/red]MailBody[red]'][/red], $mailheaders);


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, Southbeach, I think that helped. Or at least it gave me a something different. Beforehand the php page showed correctly, it just didnt do the email action. After adding the code you gave me, it showed a blank page. But I think I realized another problem that I didn't notice before.

Page3.asp is not pulling the information over like it should. This page should display the email info:
From: (user name)
To: (dc-sop and approver emails from database)
CC: (user name and trainer emails from database)
Subject: (subject line)
It has some of the info, but not all of it. Its pulling the user name and the permanent info of dc-sop, but its not pulling the dynamic info of the trainer and approver emails (which it should get from the previous page which pulls it from the database).

A whole different problem. My biggest problem with these pages is that I have no idea how anything is connecting to the database, and that might be the problem. Mid-May everything on the site quit working and wouldn't pull from the database. The person who was in this position before me managed to get everything to connect back to the database, but she didn't know how to fix the emails, so thats been down this whole time. But maybe if we can get page3 to connect correctly, it will all work again.....I'm going to try to talk w/ her (almost impossible to get a minute of her time), but I'd love to hear from anybody that has any more suggestions.
 
Its the PHP page displaying the information?

the each statements there should cause it to display the contents of the variables.

You still need to use the POST variables when sending the email As I posted below.

If the variables are not being displayed, then they not being sent or populated by the ASP page.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
No, its completely blank, with both what you gave me and what southbeach sent in.

Would that happen if nothing was attached to one of the variables (i think you answered that w/ your last sentence) because I think that the ASP page isn't pulling the info from the database like it should for the body so the whole thing is breaking down. If this is true, then hopefully getting that last asp page to connect over should fix it......hopefully......
 
Th easiest way to make sure if the last ASP page is actually getting the information is to take a look at the source code for the page after its loaded.

Look at the form you posted and see if the hidden values have anything inside the value attributes.

Since its generating hidden fields to pass the information taking a look at the source code, should show values for the hidden fields there instead of the ASP code.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ok, that is it. None of those hidden inputs are showing up in the code after its loaded. The only thing listed is this:
<input type="submit" value="Submit">

What can I do to get this info to post?
 
Wait I have it!!!!!!!

I changed the action from Post to Get and changed the email from Post to Request.

That pulled over almost everything. The emails are going out, but they are missing who some information on who they go out to.

If I can't get these variables made and added in here, then I can just manually forward the email after I receive it (cuz I get a copy of every email anyway).

Thank you both so much for all your help!!
 
Do this, post the code for both your 3.asp before you submit the form and 4.php after 3.asp is submitted.

Also, post your 4.php code as is right now ...

As a developer, I have learned that we are at error more often than the command interpreter. [smile]

Lets take a final look at both programs ...

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top