View Full Version : Need some help with php
NewComputer
Sep 4th 2004, 6:47 pm
I am getting an error on my new submission form. Here is the error after submitting:
Warning: mail() expects at most 5 parameters, 6 given in
and here is my code:
<?php
$to = "test@test.com";
$from = "From: contact-form@test.com\n";
mail($to, $_POST["contact-name"], $_POST["contact-email"], $_POST["contact-subject"], $_POST["contact-message"], $from);
?>
Obviously I have one too many parameters, but I don't know how to rewrite it to make it work. Thanks in advance. I am trying to learn php in greater detail, but this is frustrating as...
exam
Sep 4th 2004, 7:09 pm
look at the ref page for mail() on php.net (http://www.php.net/manual/en/function.mail.php). There are 4 clear examples of usage. Hope it helps.
-d-
exam
Sep 4th 2004, 7:17 pm
Looking at your post, this is probably what you want to do.
$content = "Name: " . $_POST["contact-name"] . "\n";
$content .= "Email: " . $_POST["contact-email"] . "\n";
$content .= "Subject: " . $_POST["contact-subject"] . "\n";
$content .= "Message: " . $_POST["contact-message"] . "\n";
mail($to, "Website form submission", $content);
NewComputer
Sep 4th 2004, 8:01 pm
Thanks Exam,
that seemed to do the trick. How do I get the results to display in a more readable manner? Right now they come through compiled. I would almost like it to come through as displayed on the contact page seen here:
http://www.newcomputer.ca/contact-us.php
Thanks again for your help. I don't need the layout, but would like the spaces.
sarahk
Sep 4th 2004, 10:03 pm
you can use "\t" for a tab space or just add the spaces. It's annoying but spaces only work in the middle of strings, not at the beginning of lines.
Sarah
NewComputer
Sep 5th 2004, 7:45 am
Thanks Sarah,
I have been really surprised that there is not a 'return' function for the actual email display.
The closest I can come is configuring it using \n and \t, but this get altered as the message, email etc... get shortened or extended.
exam
Sep 5th 2004, 7:04 pm
You can format the message that is to be sent however you want. You could make it show up in your email as:
---------------------------
Name: XXXX
---------------------------
Email: XXXX
---------------------------
Subject: XXXXX
---------------------------
Message:
XXX
XXX
XXX
---------------------------
Just put it all in the content variable above. If your email reader is html compliant you could even format it better.
If you want more help, you can post an example of how the email is displayed and how you would like it to be displayed.
-d-
NewComputer
Sep 5th 2004, 8:10 pm
Thanks again exam,
currently, the email comes to me as such:
Name: test Email: test@test.com Subject: Test Message: This is a test
Here is the <php>:
<?php
$to = "test@test.ca";
$from = "From: test@test.ca\t";
$content = "Name: " . $_POST["contact-name"] . "\t";
$content .= "Email: " . $_POST["contact-email"] . "\t";
$content .= "Subject: " . $_POST["contact-subject"] . "\t\t";
$content .= "Message: " . $_POST["contact-message"] . "\t";
mail($to, "Website form submission", $content);
?>
I would like to have it display as such:
---------------------------
Name: XXXX
---------------------------
Email: XXXX
---------------------------
Subject: XXXXX
---------------------------
Message:
XXX
XXX
XXX
---------------------------
Which is what you typed above. I have tried both the \n and \t and multiples of both, neither of which have worked.
mushroom
Sep 5th 2004, 8:14 pm
Thanks Sarah,
I have been really surprised that there is not a 'return' function for the actual email display.
The closest I can come is configuring it using \n and \t, but this get altered as the message, email etc... get shortened or extended.
Try
\r\n
works for me.
NewComputer
Sep 5th 2004, 8:17 pm
I have implemented and I am just waiting for the reply....
NewComputer
Sep 5th 2004, 8:20 pm
Thanks Mush,
If I repeat those variables will it put another space?
\r\n\r\n ?
Trance-formation
Sep 5th 2004, 8:20 pm
I would like to have it display as such:
---------------------------
Name: XXXX
---------------------------
Email: XXXX
---------------------------
Subject: XXXXX
---------------------------
Message:
XXX
XXX
XXX
---------------------------
If you do a return within the quoted string, that shows up as a return in the variable... so
$message = $fromname . " sends the following link request";
$message = $message . "
Link URL = ". $linkurl;
$message = $message . "
Site Name = " . $sitename;
$message = $message . "
Description = " . $description;
$message = $message . "
Return Link = " . $returnlinkurl;
Gives me
fromname sends the following link request
Link URL = linkurl
Site Name = sitename
Description = description
Return Link = returnlink
NewComputer
Sep 5th 2004, 8:24 pm
Thanks Trance,
but I am having problems with the email display, not the content. Thanks for the input, maybe I missed something in your post?
Trance-formation
Sep 5th 2004, 8:31 pm
Thanks Trance,
but I am having problems with the email display, not the content. Thanks for the input, maybe I missed something in your post?
Sorry, not being clear
In PHP, if you write a string as follows
<?php
$string="this appears on this line
----------------------------
but this appears on this line";
?>
and send it via email, it will be recieved as follows
this appears on this line
----------------------------
but this appears on this line
mushroom
Sep 5th 2004, 8:55 pm
Thanks Mush,
If I repeat those variables will it put another space?
\r\n\r\n ?
Yes (another line feed), I leave a space between them myself
\r\n \r\n
exam
Sep 6th 2004, 8:47 am
Try something like this:
$content = "\r\n------------------------------------\r\n";
$content .= "Name: " . $_POST["contact-name"] . "\r\n";
$content .= "------------------------------------\r\n";
$content .= "Email: " . $_POST["contact-email"] . "\r\n";
$content .= "------------------------------------\r\n";
$content .= "Subject: " . $_POST["contact-subject"] . "\r\n";
$content .= "------------------------------------\r\n";
$content .= "Message:\r\n" . $_POST["contact-message"] . "\r\n";
$content .= "------------------------------------\r\n";
mail($to, "Website form submission", $content);
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.