Hope someone can help... Im no programmer and it will no doubt show in my questions...

I have an iframe with the source of:

    email.php?ID=[email]

The ID is passing an email address which will be different every time, I would like to use this variable as the address to submit the form to.

The form page (for testing) is a very simple single input field and submit button using a form created with 'Simfatic Forms'

The email.php code is as follows:

    <?PHP
    require_once("./includes/test-lib.php");
    $formmailobj =  new FormMail("test");
    $formmailobj->setFormPage(sfm_readfile("./templ/test_form_page.txt"));
    $formmailobj->setFormID("ed3317e6-39ad-4dca-96d9-137b3f4d22f2");
    $formmailobj->setFormKey("c1e8cb6f-1598-4b2f-b6af-9ea684a7fda8");
    $formmailobj->setEmailFormatHTML(true);
    $formmailobj->EnableLogging(false);
    $formmailobj->SetDebugMode(true);
    $formmailobj->SetFromAddress("sender@website.com"); 
    $formmailobj->SetCommonDateFormat("m-d-Y");
    $formmailobj->SetSingleBoxErrorDisplay(true);
    $fm_installer =  new FM_FormInstaller();
    $formmailobj->addModule($fm_installer);

    $formmailobj->setIsInstalled(true);
    $formfiller =  new FM_FormFillerScriptWriter();
    $formmailobj->addModule($formfiller);

    $formmailobj->AddElementInfo("Name","text");
    $page_renderer =  new FM_FormPageRenderer();
    $formmailobj->addModule($page_renderer);

    $validator =  new FM_FormValidator();
    $validator->addValidation("Name","req","Please fill in Name");
    $formmailobj->addModule($validator);

    $data_email_sender =  new FM_FormDataSender(sfm_readfile("./templ/test_email_subj.txt"),sfm_readfile("./templ/test_email_body.txt"),"forms<forms@simfaticforms.com>");
    $data_email_sender->AddToAddr("<name@website.com>");
    $formmailobj->addModule($data_email_sender);

    $tupage =  new FM_ThankYouPage(sfm_readfile("./templ/test_thank_u.txt"));
    $formmailobj->addModule($tupage);

    $formmailobj->ProcessForm();
    ?>

I have tried to change line 29:

$data_email_sender->AddToAddr("<name@website.com>");

replacing the part <name@website.com> with the variable but no success.

I think its to do with the variable not being posted, but dont know where to start... As I say, im new to programming and this is a bit advanced for me, so be kind! :-)

The email variable is posted in the URL so can be accessed via $_GET['ID'].

This should work:

$data_email_sender->AddToAddr($_GET['ID']);

The email variable is posted in the URL so can be accessed via $_GET['ID'].

The variable can definately be accessed as I can show it on the page using:

<?php echo $_GET['ID']; ?>
$data_email_sender->AddToAddr($_GET['ID']);

This is what I thought it should be, however I get an error from the included 'test-lib.php' page stating "554 Error: no valid recipients". Any further ideas?

Hardcode the email address and see if that throws an error. If it's in a valid email format and it still throws an error, i would look at how the email addresses are validated in the class before sending.

Hardcode the email address and see if that throws an error. If it's in a valid email format and it still throws an error, i would look at how the email addresses are validated in the class before sending.

Using a real email address works fine, the form submits with no errors and the email is received instantly.

Ok, then it must be the email address contained in the $_GET['ID'], I would run the form as normal a few times but echo the $_GET['ID'] to see what the exact value is.

The 'ID' shows correctly every time using

<?php echo $_GET['ID']; ?>

or 

echo $_GET['ID'];

Ive tried various ways of using the variable but to no success, I thought it was a simple case of changing it like pritaeas suggested.

Just ignore my previous discussions, due to design changes Ive had to abandon that code and start with this. For a multitude of reasons the form needs to be in an iframe using the code I included at the start of this thread.

Ok, when you hard coded the email address, did you put <> either side (<me@mydom.com>), or just the address in quotes ("me@mydom.com")?
If the first instance, you need to concatenate "<".$_GET['ID'].">", if the second instance, I have no idea what the problem is without seeing the addresses that you are using.
I do have one doubt in my mind, and that is the fact that the form is in an iframe, but you are able to echo the necessary variable on the necesary page so...

Thanks for all your help so far. Email hard coded and working as follows:

$data_email_sender->AddToAddr("<me@mydoamin.com>");

I can definately display the variable at the end of the page using:

<?php echo $_GET['ID']; ?>

I have tried to include the variable as follows:

$data_email_sender->AddToAddr("<".$_GET['ID'].">");

However, on submitting the form I receive an error: 554 Error: no valid recipients.

Im lost. Maybe it's the iframe causing the problem after all.

Ok, its not the iframe. if I link to the page containing the form and view it normally (not in an iframe) the same problems are happening... fine with a hard code email address, not working with .$_GET['ID'].

Update:

If I use a hard coded email and use the variable within the form, the form submits fine but the variable is not showing in the recevied email... does this reveal anything?

Is it possible that the script you are using has a place to add valid recipients as an attempt to stop somebody using your form as a mailshot device? The error could mean that the script has received the email address and it is not malformed, but that it is not on the list of valid recipients. The only other thing I can think is that method requires your input to be quoted - "<$_GET['ID']>", but that would be unusual I think. You could kill the script in the class itself - echo $_GET['ID'] on the first line of the AddToAddr() and see what the value is. Maybe if you post the contents of the class that contains the method we an see more.

Ive looked into 'valid recipients' and there is none. I can hard code the email to anything I want and it works.

The value thats being passed is showing correct, me@mydomain.com
(real email hidden for security).

If I hard code the email and try to put the variable in line 10 as the sender the form submits fine and the email is received, however the 'from' is empty in outlook.

There's a little difference in your other thread. What happens if you do:

$data_email_sender->AddToAddr('John Doe <' . $_GET['ID'] . '>');

$data_email_sender->AddToAddr('John Doe <' . $_GET['ID'] . '>');

This brings up the following error on submit:

554 Error: no valid recipients.

I may have to scrap this form method and start from basics to see if the variable can be passed & emailed successfully at all! :-(

Okay here is something different...

If I hard code my email into the $data_email_sender, the form submits and I receive the email correctly. However, if I put the variable into line 10 of my code (the from section) using the line of code from pritaeas:

    $formmailobj->SetFromAddress('John Doe <' . $_GET['ID'] . '>');

The form submits and I receive an email with the 'From' as 'John Doe' but no variable is included with the name.

Does this mean anything? Seems the variable is not being recognised, so nothing is passed. Does this mean it is not posting correctly? Im lost.

Are you sure no variable is included in the name? In my gmail it hides the email address from me and only shows me the name of the sender. What if you hard code the from address, does it show then? What mail class are you using? Can you point us to the website?

You can look at the test pages here: Click Here

Note: Ive gone back to a basic form incase simfatic forms are causing any problems.

Ive setup a basic php form that works fine using hard coded emails & subject text.

I am leaving the email address as hard code, submitting the form works fine and everything is received.

However when I use the variable as the subject line, so I know the emails are working, im not receiving any subject text in the emails. (this works when subject is hard code).

Im sending the variable to the form page by adding ?ID=subjecttitle to the end of the address line: test.php?ID=subjecttitle

Im obviously overlooking something very basic here. Im doubting my sanity!

Hey again :)
First, good job with the pages showing your testing!
You send the variable via the URL so it must be retrieved via the $_GET array on the test.php page. This works fine with the link you have at the bottom of the page because the &name=value pair is certainly passed in the link. However, when the form is submitted using the submit button the $_GET variable is not available. This is because the &name=value pair is not in the url.
So how does the form page know know where to redirect to when it is submitted? Because the URL is in the action declaration of the form - action="/test.php". So if you want to take a variable from the url, you could add it to the action - action="/test.php?foo=bar", which will acheive the desired effect.
The problem is that you are declaring the variable on the outer page (presumably index.php), and then trying to collect that variable in delete.php, this will never work because the variable was never available to the page delete.php with the submit button.
Hope this helps, let us know how you get on.

Great thanks, that makes sense.

When you say "you could add it to the action - action="/test.php?foo=bar"..." im unsure as to which action (ive alot to learn). My test.php page is as follows, where should it be added?

<?php 

$subject = '<' . $_GET['ID'] . '>';

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{

    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $user_message = $_POST['message'];
    ///------------Do Validations-------------
    if(empty($name)||empty($visitor_email))
    {
        $errors .= "\n Name and Email are required fields. ";   
    }
    if(IsInjected($visitor_email))
    {
        $errors .= "\n Bad email value!";
    }
    if(empty($_SESSION['6_letters_code'] ) ||
      strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
    {
    //Note: the captcha code is compared case insensitively.
    //if you want case sensitive match, update the check above to
    // strcmp()
        $errors .= "\n The captcha code does not match!";
    }

    if(empty($errors))
    {
        //send the email
        $to = 'info@directoryfox.com';
        $subject = $subject;
        $from = $visitor_email;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

        $body = "A user  $name submitted the contact form:\n".
        "Name: $name\n".
        "Email: $visitor_email \n".
        "Message: \n ".
        "$user_message\n".
        "IP: $ip\n";    

        $headers = "From: $from \r\n";
        $headers .= "Reply-To: $visitor_email \r\n";

        mail($to, $subject, $body,$headers);

        header('Location: thank-you.html');
    }
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Contact Us</title>
<!-- define some style elements-->
<style>
label,a, body 
{
    font-family : Arial, Helvetica, sans-serif;
    font-size : 12px; 
}
.err
{
    font-family : Verdana, Helvetica, sans-serif;
    font-size : 12px;
    color: red;
}
</style> 
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>  
</head>

<body>
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
<p>
<label for='name'>Name: </label><br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
<p>
<label for='email'>Email: </label><br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
<p>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input type="submit" value="Submit" name='submit'>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
    var img = document.images['captchaimg'];
    img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>

<BR><BR><BR><BR>
Variable passed = <?php echo $_GET['ID']; ?>
</body>
</html>

Hey again :)
line 119:
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>
PHP parses the variable $_SERVER['PHP_SELF'] and echoes the current URL as the action, so whatever you name the file, the correct URL will be in the action declaration.
Now you want that to stay the same, but to add some more text to it also (it's called concatenation where you extend a string).

$string = "this" . " is"  . " a " . "string";
echo $string; //outputs "this is a string"

So you need to concatenate $_SERVER['PHP_SELF'] and "?ID=" and $_GET['ID']
Look here for some more info on concatenation - http://webdesignertutorials.com/tutorials/concatenating-php-strings.html and post back if you have any more problems.
Good luck! :D

AWESOME!!! Thanks!!!

I created this:

$string1 = $_SERVER['PHP_SELF'];
$string2 = '?ID=';
$string3 = $_GET['ID'];

Changed action= to this:

action="<?php echo htmlentities($string1.$string2.$string3); ?>"> 

Variable received in the email, and it all works within an iframe.

Huge thanks for your help with this one, couldnt have done it without you. Will try and go back to my original form and see if I can fix that one. ;-)

Nice one!
Ahhh, I have a warm glowy feeling inside :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.