asmithdesigns Posted April 9, 2008 Share Posted April 9, 2008 Hey all! Here is a run down of what I am trying to figure out... The user will put their e-mail address in a text field. Once they hit the submit button, they will receive an e-mail at the address that they specified. That is the short version... let me explain in more detail. I am creating a site for an art gallery. Due to the rules for this art gallery, they are not allowed to post prices online for their art. They are however, allowed to send user's the prices through e-mail. So, every piece of art that they view will have a price attached to it. I just need that price to be sent to their e-mail address, when they request it. I have found many tutorials on how to send an e-mail address from that user's e-mail to mine... but none that can tell you how to actually send it to their e-mail address. So, that is where I am at! Hopefully you all can shed some light into this! Thanks in advance!! Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 9, 2008 Author Share Posted April 9, 2008 One other thing. I was also hoping that this could sign them up for a "Newsletter" at the same time. However, this is far less important that figuring out how to send them an e-mail with pricing information. Anyhow, just though I would throw that in there. Does anyone have any ideas? I've been on several other pHp website's forums and have had no luck with help Thanks!! Quote Link to comment Share on other sites More sharing options...
Kieran Menor Posted April 9, 2008 Share Posted April 9, 2008 http://www.php.net/manual/en/function.mail.php Feel free to ask when you've read that page. Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 9, 2008 Author Share Posted April 9, 2008 Thanks for posting that! So, as I was reading through that page... it seems that most of those are just sending an e-mail to a pre-defined address (for example, all of the e-mails go to one e-mail adress). Not to an address specified by the user. (whatever the user types in the form.) I think that one of the replies on that page has something close to what I am looking for.... this is the post.... <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> Is that what I should be looking at? Or... am I missing something? Thanks again!!! Quote Link to comment Share on other sites More sharing options...
Kieran Menor Posted April 9, 2008 Share Posted April 9, 2008 bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) Well, instead of just putting a static e-mail address in $to, you could put in $_POST['email'] or something similar. Example: <!-- This HTML comment is placeholder for the image --> <form action="sendprice.php" action="post"> <input type="hidden" name="imageid" value="INSERT_IMAGE_ID_HERE"> E-mail: <input type="text" name="email"> <input type="submit" name="send" value="Request price"> </form> In sendprice.php, you could have: <?php // Connect to database and do various stuff $query = mysql_query( "SELECT price FROM gallery WHERE image_id = " . intval( $_POST['imageid'] ) ); $price = mysql_result($query, 0, 0); $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"; if( mail($to, $subject, $message) ) { echo "Thank you for using our mail system. You should be recieving an e-mail soon."; } else { echo "An error happened while trying to send the e-mail. Please try again soon!"; } ?> Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 9, 2008 Author Share Posted April 9, 2008 Very cool! Thanks for taking your time to explain it to me, I really do appreciate it. One more question.... so, in my database I just need to have "price" and "gallery" tables? Thanks again! Quote Link to comment Share on other sites More sharing options...
Kieran Menor Posted April 9, 2008 Share Posted April 9, 2008 Well, the price would be a column in the gallery table. But it depends, how do you store information about the images at the moment? Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 9, 2008 Author Share Posted April 9, 2008 Well, I know that using a database would greatly simplify things. However, due to my "novice" experience with pHp and databases... I was just going to have each form be separate from each other. All of the images are on separate pages. So, on each page there will be a different e-mail form to get the pricing for that particular piece. I am doing this to try and avoid having to use databases. It is more work, but I will be able to understand it better that way. Quote Link to comment Share on other sites More sharing options...
Kieran Menor Posted April 9, 2008 Share Posted April 9, 2008 Ah, I see. In that case, you could do something like this: Example: <!-- This HTML comment is placeholder for the image --> <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> In sendprice.php, you could have: <?php $to = $_POST['email']; $subject = "Image price request from example.com"; $message = "Thank you ... blah blah blah ... The price for the selected image is " . $_POST['price'] . " blah blah Sincerely, asmithdesigns"; if( mail($to, $subject, $message) ) { echo "Thank you for using our mail system. You should be recieving an e-mail soon."; } else { echo "An error happened while trying to send the e-mail. Please try again soon!"; } ?> The only drawback is that you are able to view the price by viewing the source. Another posibility is simply adding this to all gallery pages: <?php $price = "£10.00"; if(isset($_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"; if( mail($to, $subject, $message) ) { echo "Thank you for using our mail system. You should be recieving an e-mail soon."; } else { echo "An error happened while trying to send the e-mail. Please try again soon!"; } } else { // display the page } ?> You can always toy around with how the error/success messages are shown, and such. Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 9, 2008 Author Share Posted April 9, 2008 You answered exactly what I was looking for!! Thank you soo much! I definitely see you point about being able to see the pricing by viewing the source. However... one thing I forgot to mention is that I am doing this website in Flash. So... I might not have an issue with that. Anyhow, thanks again! Much Appreciated. Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 So, I have everything set up and I keep getting the error message "An error happened while trying to send the e-mail. Please try again soon!" I mean, I should get that message if something is wrong which is good that the script is working. Any ideas? Do I have to put any connection settings for my domain? I use Bluehost.com... everything should be good to go. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 11, 2008 Share Posted April 11, 2008 <?php $price = "£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 { // display the page } ?> Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 Thanks for the reply! I tried that new code... and it just goes to a blank page. The blank page is where you put // display the page To make sure that is what it was really going to, I put echo "huh?"; and sure enough it went there. So, we know that it is not erroring out. Do I not have to tell the php script what e-mail address these e-mails are coming from.... or does Bluehost do that automatically? Again, thanks for all the help!! Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 11, 2008 Share Posted April 11, 2008 it will work if you tell it what to do if it is submitted. if you want it to redirect to another page try using <?php }else{ header("main.php"); }?> Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 I tried that, instead of using main.php I used index.html, which is in the same directory. Here is what I get... Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@asmith-design.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at asmith-design.com Port 80 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 11, 2008 Share Posted April 11, 2008 header('Location: http://www.example.com/'); Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 Thanks for the clarification!! I am able to be succesfully re-directed to the new page, without any errors. The problem remains that it is not sending the e-mails. I've tried going to three different addresses. Any ideas? Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 So, I think that my problem is that I am not giving a connect to Bluehost.com's e-mail? I made sure that I have an active e-mail adress set up with them. So, everything should be working. Do I need to also have some kind of connection scripts in this as well? For example... my incoming mail server, outgoing, etc ? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 11, 2008 Share Posted April 11, 2008 nope it should work. might wanna ask bluescript if they have the mail function for PHP enabled though Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 Thanks for all your help man! I went ahead and posted on bluehost.com's forums... so if I get a response that fixes the issue, I will be sure to let you know. Thanks again! Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 11, 2008 Author Share Posted April 11, 2008 I did find out that BlueHost.com uses pHp 5.5... could that be contributing to the issue I am having? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 12, 2008 Share Posted April 12, 2008 no the issue is not the code. it is something Bluehost has disabled in php.ini Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 12, 2008 Author Share Posted April 12, 2008 Ah, I see what you mean. So, is there a way for me to edit the php.ini.... or does it depend on each different host? In other words, is there are way I can access the php.ini? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 12, 2008 Share Posted April 12, 2008 most hosts dont allow you to access this file you would have to ask them if they have the PHP mail function enabled if that is the case then there is something we are missing in the code Quote Link to comment Share on other sites More sharing options...
asmithdesigns Posted April 12, 2008 Author Share Posted April 12, 2008 I was able to succesfully copy my php.ini file into my public_html folder. I tried changing a few things without any luck. Hopefully they will get back with me soon! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.