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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
05-12-2008, 11:09 PM
#1
Senior Member
Registered: Feb 2007
Location: The Tropics
Distribution: Slackware & Derivatives
Posts: 2,472
Rep:
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?
05-13-2008, 03:44 PM
#2
Senior Member
Registered: Feb 2007
Location: The Tropics
Distribution: Slackware & Derivatives
Posts: 2,472
Original Poster
Rep:
This can't seriously be that hard for all you geniuses
btw, I don't get any type of error from mailer-daemon either.
05-14-2008, 12:11 AM
#3
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794
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 .
05-14-2008, 09:21 PM
#4
Senior Member
Registered: Feb 2007
Location: The Tropics
Distribution: Slackware & Derivatives
Posts: 2,472
Original Poster
Rep:
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 ?
05-14-2008, 11:41 PM
#5
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794
Did the link that I gave you not help?
05-15-2008, 03:44 PM
#6
Senior Member
Registered: Feb 2007
Location: The Tropics
Distribution: Slackware & Derivatives
Posts: 2,472
Original Poster
Rep:
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 .
05-15-2008, 11:45 PM
#7
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794
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 ">$value<<BR>\n";
$message .= $key . ': ' . $value;
$message .= "\n";
}
echo ">$message<<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.
All times are GMT -5. The time now is 09:02 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News