Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Posts
    58

    E-mail in PHP for a newbie

    Hello,

    Currently, I'm using the rather crude code to send an e-mail from a webpage in PHP:

    <?
    mail('question@server.com',$_POST['txtEmail'],$_POST['body']);
    ?>

    Ideally, I want to have it post who it's from (txtEmail), a subject (txtSubject) and the e-mail body (body), although currently, I can get away with it e-mailing the txtEmail as the subject and the body as the mail e-mail. How can I change the subject to a my own and who it's from to the txtEmail variable??

    Many thanks

  2. #2
    Join Date
    May 2004
    Location
    United Kingdom
    Posts
    522
    *> If my post was helpful you could add to my Reputation by clicking the Icon. Thanks!!!! <*

  3. #3
    Join Date
    Jul 2004
    Location
    N29° 22.725' X W95° 6.452'
    Posts
    343
    If I am following what you want, you want the email that is sent to 'question@server.com' to display the subject, email body and the persons email that sent it?

    If that is what you are looking to do then it is quite easy. There is a 4th optional parameter that you can include in the mail function. What I do is format it like this:
    $mailheaders = "From: $_POST[fromname] <$_POST[fromaddress]>\n";
    and add it to the mail function:
    mail($recipient, $subject, $msg, $mailheaders);

    Now when you get an email that was sent from your submit form it will be formatted with the subject, message body and the persons name and email that sent it.

    Hope that helps you as I am not 100% clear on what you are trying to do but I think that is it.

  4. #4
    Join Date
    Mar 2004
    Location
    Manchester, England
    Posts
    319
    Here is a function I use for sending mail. I created it myself.

    function sendMail($to,$from,$subject,$body)
    {
    $headers="From: " . $from . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    mail($to,$subject,$body,$headers);
    }

    Should be what you need.

    Your idea is dumb!

    @njl - YEP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •