PHP Pop up Contact form?

Matthew T

New member
Hi

I have a jquery pop up contact form, which works fine, except for on the PHP back end. The script defines a variable of siteEmail which you would put the e-mail address you want the contact form to be sent to. However the contact popup is on a member page, so I need to pull the members e-mail address from the database which is stored as $email and insert that into where the contact form is sent.

I have pasted the php code below, if you have any ideas please let me know


<?php

class ContactPop {
/****** config *********/

// the email to which you want to send the info from the contact form
var siteEmail = $email

// the title of the emails that the form sends
var $emailTitle = 'You Have Been Contacted';

var $thankYouMessage = "Thank you for me, I will get back to you shortly.";

/******* end config ********/


var $error = '';

function getFormHtml($ajax = 0) {

$postedName = $_POST['name'];
$postedEmail = $_POST['email'];
$postedMessage = $_POST['message'];

$formHtml = '';

// send congratulations message
if ( isset($_POST['httpReferer']) && !$this->error ) {
$out = '<p id="contact-pop-error" class="formItem">' . $this->thankYouMessage . '</p>';

if ( $ajax ) $out .= '<a href="#" class="close-overlay">Close</a>';

return $out;
}

if ( $this->error ) $formHtml .= '<p id="contact-pop-error" class="formItem">' . $this->error . '</p>';


$httprefi = $_SERVER["HTTP_REFERER"];

$cancelLink = $ajax ? '<a href="#" class="close-overlay">Cancel</a>' : '';

$formHtml .= <<<EOT

<input type="hidden" name="httpReferer" value="$httprefi" />

<div class="formItem">
<label>Name:</label>
<input type="text" name="name" class="inputText" value="$postedName" size="35" />
</div>

<div class="formItem">
<label>Email:</label>
<input type="text" name="email" class="inputText" value="$postedEmail" size="35" />
</div>

<div class="formItem">
<label>Message:</label>
<textarea name="message" class="textarea" rows="7" cols="38">$postedMessage</textarea>
</div>

<div class="formItem">
<input type="submit" value="Send Message" class="submit" /> $cancelLink
</div>

EOT;

return $formHtml;
}

function checkEmail($emailAddress) {
if (preg_match('/[^\x00-\x20()<>@,;:\".[\]... $emailAddress)){
$emailArray = explode("@",$emailAddress);
if (checkdnsrr($emailArray[1])){
return TRUE;
}
}
return false;
}

function processForm() {

// check data
if ( !$_POST['name'] ) $this->error .= 'Please enter your name
';
if ( !$this->checkEmail( $_POST['email'] ) ) $this->error .= 'Please enter a valid email address
';
if ( !$_POST['message'] ) $this->error .= 'Please enter a message
';

if ( !$this->error ) $this->sendFormEmail();
}

function sendFormEmail() {
$message = "Name: " . stripslashes($_POST['name']) .
"\nEmail: " . $_POST['email'] .
"\n\nMessage: " . stripslashes($_POST['message']);

if ( $_POST['ajaxForm'] ) $message .= "\n\nFrom a Contact-Pop Form on page: " . $_SERVER["HTTP_REFERER"];
else $message .= "\n\nReferrer: " . $_POST['httpReferer
 
Back
Top