View Full Version : pHp E-mail Problem....
asmith-design
04-11-2008, 12:42 PM
Hey all,
Here is the low down and my code....
I have a form that a user can put their e-mail address in. It will then send them an e-mail with the price and information for an item. Here is my code...
<html>
<head><title></title></head>
<body>
<form action="sendprice.php" action="post">
<input type="hidden" name="price" value="£10.00">
E-mail: <input type="text" name="email">
<input type="submit" name="send" value="Request price">
</form>
</body>
</html>
<?php
$price = "&#163;10.00";
if(isset($_POST['submit'])||!empty($_POST['submit'])) {
$to = $_POST['email'];
$subject = "Image price request from example.com";
$message = "Thank you ... blah blah blah ...
The price for the selected image is " . $price . "
blah blah
Sincerely,
asmithdesigns";
$mail= mail($to, $subject, $message);
if($mail) {
echo "Thank you for using our mail system. You should be recieving an e-mail soon.";
}
else if(!$mail) {
echo "An error happened while trying to send the e-mail. Please try again soon!";
}
}
else {
header('Location: http://www.asmith-design.com/');
}
?>
I have had that code tested on other web hosting providers, including another domain I have through iPowerweb.... but it will not work with bluehost.
Anyone have any suggestions? Thanks! :)
charlesp
04-11-2008, 04:19 PM
The other hosting companies probably still use php 4.x Bluehost uses php 5.2.5
asmith-design
04-11-2008, 05:36 PM
Ah I see. Thanks for the response!! Do you have any suggestions as to how I can get this to work?
Thanks again! :D
asmith-design
04-11-2008, 09:21 PM
I had gotten some advice from some of my co-workers... they are thinking it is an issue with BlueHost having something disabled in the php.ini file. The code that I have there works with the new and old versions of php.
Anyway that this could be contributing? Or, do I need to have my outgoing, incomming, smtp information in there somewhere?
felgall
04-12-2008, 12:37 AM
You are using the wrong field names to reference the values passed from the form.
You have $price where you should have $_POST['price']
The copy from $_POST['price'] into $price only happens automatically when the Register Globals security hole is enabled. This was the default up until PHP 4.1. In PHP 4.2 the default was changed to off requiring the fields to be assigned within the code (unless you change the setting). The Register Globals setting itself has already been removed completely from PHP6 which is currently still in development as there is no need whatever for enabling such a security hole if the code is written properly.
Obviously your old hosting either had a really antiquated version of PHP (4.1 or earlier) or had changed the default in the version that they are using in order to allow posting values to any field in the script instead of just those you have in your copy of the form.
All you need to do is add the following line to the top of your code to fix this:
$price = $_POST['price'];
asmith-design
04-12-2008, 01:03 AM
Thanks for the reply! I went ahead and added that line to the top of my script... however, it is still not able to actually send the e-mails. I tried sending it to two different addresses.
I am wondering if there is something I need to change in the php.ini.
Is there anyway that someone could help me with that?
charlesp
04-12-2008, 02:40 AM
You need to have a copy of php.ini in every folder that uses php.
asmith-design
04-12-2008, 10:24 AM
Thanks. I actually do have the php.ini file in my public_html directory as well as in every sub-directory.
It is still not working. Do I not have to edit the php.ini file to get it to work properly?
I hate to be so persistant... but this is something that should definately be working fairly easily.
Thanks!
IvanAkimov
04-12-2008, 10:43 AM
you might want to mess around with headers for the function also. i had a problem once where i specified the "from:" field with an email that didn't exist (like auto-respond@domain.com) and it wouldn't send an email because of that.
charlesp
04-12-2008, 03:16 PM
Try adding this to your script:
if (isset($_POST['email'])) {
//send email
$name = $_POST['name'];
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['comments'] ;
mail( "$email", "$subject", $message, "From: $email" );
echo "Thank you for using our mail form. You will have a reply within 24 hours.";
} else {
// display the form. Or whatever.
Adjust it to fit your form or adjust your form to fit the script.
Is your script even giving you your "An error happened while...." message? or is it just sending you to your homepage?
I would change your
if(isset($_POST['submit'])||!empty($_POST['submit'])) {
to
if ($_POST['submit'] == "Request price") {
You might want to add some other form validation as well.
-
felgall
04-12-2008, 04:33 PM
You'd do better to reference $_POST or $_GET rather than $_REQUEST so as to be more specific as to how you expect the values to be passed and hence make it harder for someone to hack your script.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.