Jump to content

Sending Pre-Defined E-mail Per User Request....


asmithdesigns

Recommended Posts

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!!  ;)

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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!";
}
?>

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.  ;D

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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 {
// display the page
}
?>

Link to comment
Share on other sites

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!!

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.