LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-12-2008, 11:09 PM   #1
phantom_cyph
Senior Member
 
Registered: Feb 2007
Location: My HDD...
Distribution: WinXP for designing, Linux for life.
Posts: 2,329
Blog Entries: 1

Rep: Reputation: 45
PHP Mail function


OK, so this is similar to my old thread, but not really...

I have the html file:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
        <head>
        <meta http-equiv="Content-Type" content="text/html;
        charset=utf-8"/>
        </head>

        <title>Contact Me</title>

        <body>
                <form method="POST" action="edmanmail.php">

                        <textarea name="message" cols="50" rows="5"></textarea>
                        <br>
                        <br>
                        <input type="submit" value="Submit">
                </form>
        </body>
</html>
And the php file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
        <head>
                <title>
                        Sending email...
                </title>
        </head>

        <body>
                <center>
                <h1>
                        Your email has been sent.
                </h1>
                <?php
                        $result = mail("email@someplace.net", "WebMail",
                                $_request["message"]);
                ?>
                </center>
        </body>
</html>
However, I now get the empty email from "User for Apache" titled "WebMail".

So...2 questions. How do I change the "User for Apache" part, and how can I get the message that is entered? Any ideas as to what is wrong?
 
Old 05-13-2008, 03:44 PM   #2
phantom_cyph
Senior Member
 
Registered: Feb 2007
Location: My HDD...
Distribution: WinXP for designing, Linux for life.
Posts: 2,329
Blog Entries: 1

Original Poster
Rep: Reputation: 45
This can't seriously be that hard for all you geniuses

btw, I don't get any type of error from mailer-daemon either.
 
Old 05-14-2008, 12:11 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 10.04, Crunchbang Statler
Posts: 3,325

Rep: Reputation: 168Reputation: 168
Give it chance to go around the world or don't bump within 24 hours. Posts with 0 replies will be bumped anyway for two days, so why would you do it?

How about some debugging? Put an echo statement before sending the mail to show the message ($_request("message")). I think you will not see anything.

Try $_REQUEST instead of $_request, I think that it will do the trick.

For the 'user for apache', see http://www.php.net/manual/en/function.mail.php , additional headers.
 
Old 05-14-2008, 09:21 PM   #4
phantom_cyph
Senior Member
 
Registered: Feb 2007
Location: My HDD...
Distribution: WinXP for designing, Linux for life.
Posts: 2,329
Blog Entries: 1

Original Poster
Rep: Reputation: 45
Thank-you! The change to capital letters made it work!

The only other thing I see though is that this is who it comes from:

Quote:
User for Apache <apache@hostname.hostname.net>
How do I change it so it says something like... customer@hostname.net?
 
Old 05-14-2008, 11:41 PM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 10.04, Crunchbang Statler
Posts: 3,325

Rep: Reputation: 168Reputation: 168
Did the link that I gave you not help?
 
Old 05-15-2008, 03:44 PM   #6
phantom_cyph
Senior Member
 
Registered: Feb 2007
Location: My HDD...
Distribution: WinXP for designing, Linux for life.
Posts: 2,329
Blog Entries: 1

Original Poster
Rep: Reputation: 45
Unhappy

Using your link plus some others, I have this mail.php file:

Code:
<html>
<body>
<?php
$mailto = "phantom@mysite.net";
$subject = "Website Response";
$redirect = "../../thanks.html";

foreach($HTTP_POST_VARS as $key => $value) {

$message .= $key . ': ' . $value;
$message .= "\n";

}
if (@mail($mailto, $subject, $message)) {

header("Location: $redirect");
} else {

echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
?>
</body>
</html>
Here is my html file with the form:
Code:
<html>
<body>
<form method="POST" action="mail.php">
        <p><label for="name">Name</label>
        <input type="text" id="name" /></p><br>
        <p><label for="e-mail">E-mail</label> <input type="text" id="email" /><br /></p><br>
        <p><textarea name="message" cols="50" rows="5"></textarea></p>
        <br>
        <p class="submit"><input type="submit" value="Submit" />
        <input type="reset" value="Clear" /></p>

        </form>

</form>
</body>
</html>
Now, once again, I get the mail with nothing in it. What is wrong this time?

Last edited by phantom_cyph; 05-15-2008 at 03:45 PM.
 
Old 05-15-2008, 11:45 PM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 10.04, Crunchbang Statler
Posts: 3,325

Rep: Reputation: 168Reputation: 168
Check your error log (/var/log/httpd/error_log or similar depending on your setup). You will more than likely see an error message related to message.

Code:
$message .= $key . ': ' . $value;
$message .= "\n";
The first time that you enter the loop message does not exist yet, so the first line will fail. Add a line before the foreach with $message="";

For debugging purposes, add echo statements so you can see what happens

Code:
<html>
<body>
<?php
$mailto = "phantom@mysite.net";
$subject = "Website Response";
$redirect = "../../thanks.html";

foreach($HTTP_POST_VARS as $key => $value) {
echo "&gt;$value&lt;<BR>\n";
$message .= $key . ': ' . $value;
$message .= "\n";

}

echo "&gt;$message&lt;<BR>\n";

if (@mail($mailto, $subject, $message)) {

header("Location: $redirect");
} else {

echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
?>
</body>
</html>
The above code will tell you what is going on with your variables. Once your function is working, you can remove them.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mail-function php sharp81 Linux - Software 3 02-17-2006 09:45 AM
HELP !!! php mail function akamaru607 Programming 22 08-26-2005 02:44 PM
How does the mail function work(PHP) Alexander.s Programming 1 05-15-2005 09:02 AM
PHP - mail function saravanan1979 Programming 2 08-06-2003 01:46 AM
Using the PHP mail() Function !?!? Hdata Programming 0 06-22-2003 06:02 AM


All times are GMT -5. The time now is 06:44 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration