1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need some help with php

Discussion in 'PHP' started by NewComputer, Sep 4, 2004.

  1. #1
    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: \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...
     
    NewComputer, Sep 4, 2004 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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 4, 2004 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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);
     
    exam, Sep 4, 2004 IP
  4. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #4
    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.
     
    NewComputer, Sep 4, 2004 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    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
     
    sarahk, Sep 4, 2004 IP
  6. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #6
    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.
     
    NewComputer, Sep 5, 2004 IP
  7. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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-
     
    exam, Sep 5, 2004 IP
  8. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #8
    Thanks again exam,

    currently, the email comes to me as such:

    Name: test Email: Subject: Test Message: This is a test

    Here is the <php>:

    <?php
    $to = "test@test.ca";
    $from = "From: \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.
     
    NewComputer, Sep 5, 2004 IP
  9. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Try
    works for me.
     
    mushroom, Sep 5, 2004 IP
  10. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #10
    I have implemented and I am just waiting for the reply....
     
    NewComputer, Sep 5, 2004 IP
  11. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #11
    Thanks Mush,

    If I repeat those variables will it put another space?

    \r\n\r\n ?
     
    NewComputer, Sep 5, 2004 IP
  12. Trance-formation

    Trance-formation Peon

    Messages:
    598
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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;
    Code (markup):
    Gives me

     
    Trance-formation, Sep 5, 2004 IP
  13. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #13
    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?
     
    NewComputer, Sep 5, 2004 IP
  14. Trance-formation

    Trance-formation Peon

    Messages:
    598
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #14
    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";
    ?>
    Code (markup):
    and send it via email, it will be recieved as follows

     
    Trance-formation, Sep 5, 2004 IP
  15. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Yes (another line feed), I leave a space between them myself

     
    mushroom, Sep 5, 2004 IP
  16. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #16
    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);
     
    exam, Sep 6, 2004 IP