Jump to content

php email help/question?


newphp-er

Recommended Posts

Hi All

 

I am working on an email form that sends an email to the email address entered in the form using php as well as contains the subject.

 

However, I want the Message/body of the email to be retrieved from a database field. I know that might sound like a wierd email form, but it is what I need it to do.

 

My form already is connected to the database and I am usinga fairly basic email script.

 

So first, is it possible to actually send the contents of a database column and row through php email in the message of an email?

 

Here is some of the code:

 

 

 

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty.     */

                        			if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
							  echo "<h4>Invalid email address</h4>";
							  echo "<a href='javascript:history.back(1);'>Back</a>";
							} elseif ($subject == "") {
							  echo "<h4>No subject</h4>";
							  echo "<a href='javascript:history.back(1);'>Back</a>";
							}

							/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
							elseif (mail($email,$subject,$message)) {
							  echo "<h4>Thank you for sending email :-)</h4>";
							} else {
							  echo "<h4>Can't send email to $email</h4>";
							}

 

So how would I go about making the $message part of the code above get the data I want?

 

Thanks for any info

 

 

newphp-er

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/124019-php-email-helpquestion/
Share on other sites

Ok, I thought it was something like that, however I can't seem to get it.

 

My table is called emailinfo and my column is titled email_text

 

$query="SELECT * FROM `emailinfo` WHERE `".$email_text."`";    
$message = mysql_query($query);

 

I know this isn't exactly correct, can you clearify how to do it?

 

 

 

Thanks

 

newphp-er

Not sure about the word "associating"?

 

The form has this:

<form action="formmail.php" method="post">

 

formmail.php is where the php is that is in my first post.

 

I am also connected to my database via:

                     

mysql_connect("localhost", "User", "Password") or die(mysql_error());   
                      echo "<font color='white' face='arial'><span style='font-size: 10px;'> Connection to the  Server...<br/>";    
                      mysql_select_db("The_Database") or die(mysql_error());   
                      echo "Database Active!<br/></span></font>";

 

Not sure if this is what you mean  :)

 

Thanks

???That is a good question!

 

The form has a text field called "answer", when the viewer submits the form, the form passes on the email of the person and the code they have entered. If the code matches one of the ones in the database, it should then send the correct "email_text"  in the message of the email.

 

To clearify:

The form has a quiz question on it.

The viewer reads question and if they know the answer, they can put it in the form in one text box as well as their email addy in another. If the answer is correct (which is checked in the database), they can submit the form then they receive an automated email that I want to include the "emial_text" from the data base in the body of the email.  Usually know as $message.

 

hmmm

 

Does that help....

Thanks for your time as well!

 

 

newphp-er

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.