kevinpowertv 0 Newbie Poster

Hey guys,

I have a contact form with a image verification and a checkbox to sign up for a newsletter or not. What I'm trying to do is send an extra email to a email address if the checkbox to sign up for a newsletter is checked. The newsletter system I have signs up people by sending a email to a email address with the subject line of "subscribe". I used an array because I need to send it to two email address, but it's not a requirement. I think I got the code close, but I can't see to get it to work. Any help would be appreciated! Thanks!

Here is the HTML:

<form action="mailer.php" method="post" name="form" id="form" onsubmit="MM_validateForm('name','','R','from','','RisEmail','verif_box','','R','message','','R','newsletter','','');return document.MM_returnValue">
                    <tr>
                      <td width="42">Name</td>
                      <td width="200" colspan="2"><input name="name" type="text" id="name" size="20" value="<?php echo $_GET['name'];?>" /></td>
                    </tr>
                    <tr>
                      <td>Email</td>
                      <td colspan="2"><input name="from" type="text" id="from" size="20" value="<?php echo $_GET['from'];?>" /></td>
                    </tr>
                    <tr>
                      <td colspan="3"><textarea name="message" id="message" cols="30" rows="4"><?php echo $_GET['message'];?></textarea></td>
                    </tr>
                    <tr>
                      <td>Verify: </td>
                      <td colspan="2"><input name="verif_box" type="text" id="verif_box" size="10" />
                        <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /></td>
                    </tr>
                    <tr>
                      <td colspan="3"><input type="checkbox" name="newsletter[]" value="yes" />Sign me up for the Newsletter!
                        &nbsp;&nbsp;&nbsp;
                        <input name="Submit" type="submit" value="Submit" /></td>
                    </tr>
                  </form>

Here is the PHP (mailer.php):

<?php 
// ----------------------------------------- 
//  Contact & Newsletter Mail Form 
// ----------------------------------------- 

// load the variables form address bar 
$name = $_REQUEST["name"]; 
$subject = "Contact Form"; 
$newssubject = "Subscribe"; 
$message = $_REQUEST["message"]; 
$from = $_REQUEST["from"]; 
$verif_box = $_REQUEST["verif_box"]; 
$newsletter = $_REQUEST["newsletter"]; 

// remove the backslashes that normally appears when entering " or ' 
$message = stripslashes($message); 
$from = stripslashes($from); 

// check to see if verificaton code was correct 
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){ 

    // check if newsletter checkbox is checked and create email 
    if(isset($_REQUEST['newsletter'])) 
{ 

// create array for newsletter recipients 
    $newsyes = array( "yes" => array('newsletter1@email.com','newsletter2@email.com)); 
    foreach($_REQUEST['newsletter'] as $value){foreach($newsyes[$value] as $value2){mail($value2,$newssubject);}} 

} 

    // if verification code was correct send the message and show this page 
    mail("contact@email.com",$subject, $message, "From: $from"); 
    mail($newsyes, $newssubject, $message, "From: $from"); 
    // delete the cookie so it cannot sent again by refreshing this page 
    setcookie('tntcon',''); 
} else { 
    // if verification code was incorrect then return to contact page and show error 
    header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true"); 
    exit; 
} 
?>
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.