Jump to content


Photo

mail( Question


  • Please log in to reply
14 replies to this topic

#1 kaspm

kaspm
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 May 2006 - 05:59 PM

I have a multipage form, that I want to be sent to my email once it has been submitted. Im new to php so any help you give me I appreciate.

I have a 4 page form and have all the values "hidden" on the last page. In order to email the form, should I put this code on the last page.

<?php
$to      = 'myemail@whatever.com';
$subject = 'the subject';
$message = 'Value1''Value2''Value3''AndSoOn';
$headers = 'From: website@whatever.com' . "\r\n" .

mail($to, $subject, $message, $headers);
?>



#2 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 05 May 2006 - 06:04 PM

i don't know much php either, but is obvious to notice that the way you put the message is bad..
the values are not join in any way..

i think 'value1,value2,value3';

but then again i don't know where you getting your values from.. thats just a bad way to joing values..

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 May 2006 - 06:04 PM

That's exactly right... just make the message contain the variables. Take a shot at it and let us know what you get.

You may also want to set the return value of the mail function to a variable so you can test to see if it succeeded or not.

Info: PHP Manual


#4 kaspm

kaspm
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 May 2006 - 06:11 PM

Ok. Im getting my "values" from my form, The values are from the "name" of the form field
Example

<input type="text" name="Value1">

#5 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 May 2006 - 06:15 PM

What is the method of the form? GET or POST?

The variables will be passed to the processing script as $_GET['name'] or $_POST['name']. GET passes them in the URL... POST passes them without showing them in the URL.

Info: PHP Manual


#6 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 05 May 2006 - 06:24 PM

ok here what you should do..

the name field are values.. right..

so all you need to do is in the script make those names in to variables..

such as ..

$name = $_post['thenameofthefield'];

if you want to mail it to you use the $_post method.. $_get is for url..

after that in your message you cna just use the variable..

$messege = " hello $name";

if you want a bunch of variable you can just dump them inside the double quotes..

#7 kaspm

kaspm
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 May 2006 - 07:00 PM

Ok here is the code I got so far there are a lot more fields I want to send but I was trying it out. Now when i go to the last page of the form it doesnt show its just a plain white page. What could be the problem?
Thanks

<?php
$to = 'myemail@whatever.com';
$subject = 'Test;
$name = $_post['StartMonth','StartYear'];
$message = "$name";
$headers = 'From: website@whatever.com' . "\r\n" .

mail($to, $subject, $message, $headers);
?>

#8 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 May 2006 - 07:08 PM

You're not displaying any message ... it's probably sending the mail, but you don't have a success message or anything.

Info: PHP Manual


#9 kaspm

kaspm
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 May 2006 - 07:10 PM

its not even sending the mail

#10 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 05 May 2006 - 07:31 PM

[!--quoteo(post=371648:date=May 5 2006, 03:00 PM:name=kaspm)--][div class=\'quotetop\']QUOTE(kaspm @ May 5 2006, 03:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Ok here is the code I got so far there are a lot more fields I want to send but I was trying it out. Now when i go to the last page of the form it doesnt show its just a plain white page. What could be the problem?
Thanks

<?php
$to = 'myemail@whatever.com';
$subject = 'Test;
$name = $_post['StartMonth','StartYear'];
$message = "$name";
$headers = 'From: website@whatever.com' . "\r\n" .

mail($to, $subject, $message, $headers);
?>
[/quote]

maybe it didn't sent because you did not do the $subject right..
when working with php you really name to take your time and make sure nothing is missing.. if you just getting stared use zend! it wont let you make much mistakes..

now in $subject you have ='Test;

you see missing a '
$subject='test';

another problem i just notice.. in the $header.. you got .'\n\r".

this i think is wrong.. you dont need another . dot at the end becuase you are not connection nothing else to the headers.. so the "\\" should be with no ending dot.. the first dot connects it the last just doing nothing..

#11 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 May 2006 - 07:36 PM

You actually need a semi-colon after the $headers line.

Info: PHP Manual


#12 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 05 May 2006 - 07:41 PM

[!--quoteo(post=371661:date=May 5 2006, 03:36 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 5 2006, 03:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You actually need a semi-colon after the $headers line.
[/quote]

i even missed that.. see i'm too used to color programs.. lol

#13 kaspm

kaspm
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 May 2006 - 07:56 PM

I appreciate the help guys but even that doesnt correct the problem


#14 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 May 2006 - 08:01 PM

It should look like this:
<?php
$to = 'myemail@whatever.com';
$subject = 'Test';
$name = $_POST['StartMonth'] . $_POST['StartYear'];
$message = $name;
$headers = 'From: website@whatever.com' . "\r\n";

mail($to, $subject, $message, $headers);
?>

POST must be in caps and you can't grab 2 variables at a time.

Info: PHP Manual


#15 kaspm

kaspm
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 May 2006 - 08:53 PM

I would like to thank everyone who helped me with this. I now have it working. Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users