SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding 2nd Email Address Recipient for Form Results

    Hello

    I'm having trouble adding a second email address for my PHP form to send to when the user submits their form results. I'm using a script that requires password authentication for the original email recipient to get the email. I want to CC a second email address to receive the same email without submitting the password authentication information for the second email address as well. So far, I haven't been able to figure out how to do it. My PHP code is below. Can anyone help me make it work? Thanks in advance.

    Code PHP:
    <?php 
    if (isset($_POST["op"]) && ($_POST["op"]=="send")) { 
     
    /******** START OF CONFIG SECTION *******/
      $sendto  = email recipient (not shown);
      $subject = "Form Results";
    // Select if you want to check form for standard spam text
      $SpamCheck = "Y"; // Y or N
      $SpamReplaceText = "*content removed*";
    // Error message prited if spam form attack found
    $SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.
    </font><br><b>Your IP Number of <b>".getenv("REMOTE_ADDR")."</b> has been logged.</b></p>";
    /******** END OF CONFIG SECTION *******/
     
     
      $name = $_POST['name']; 
      $address = $_POST['address']; 
      $phone = $_POST['phone'];
      $email = $_POST['email'];
     
      $headers = "From: $email\n";
      $headers . "MIME-Version: 1.0\n"
    		   . "Content-Transfer-Encoding: 7bit\n"
    		   . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";
    if ($SpamCheck == "Y") {		   
    // Check for Website URL's in the form input boxes as if we block website URLs from the form,
    // then this will stop the spammers wastignt ime sending emails
    if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();} 
    if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();} 
     
    // Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 
      $pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 
     
      $name = preg_replace($pattern, "", $name); 
      $email = preg_replace($pattern, "", $email); 
     
    // Check for the injected headers from the spammer attempt 
    // This will replace the injection attempt text with the string you have set in the above config section
      $find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); 
      $email = preg_replace($find, "$SpamReplaceText", $email); 
      $name = preg_replace($find, "$SpamReplaceText", $name); 
     
    // Check to see if the fields contain any content we want to ban
     if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
     
     // Do a check on the send email and subject text
     if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
     if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
    }
     
    $body = " 
    ----------------------------------------------------------------------------- 
        Form Results
    ----------------------------------------------------------------------------- 
     
    Name: $name 
     
    Address: $address
     
    Direct Phone Number: $phone
     
    Email: $email
     
    _______________________________________ 
    End of Email 
    "; 
     
    $mailer = new COM("Persits.MailSender")  or die("Unable to instantiate aspemail");
    //echo $mailer->version;
    $smtp = "mail.mydomainname.com";
    $from = email recipient (not shown);
    $login = email recipient (not shown);
    $pwd = password (not shown);
    $to = email recipient (not shown);
    $mailer->Host = $smtp;
    $mailer->Username = $login;
    $mailer->Password = $pwd;
    $mailer->From = $from; // From address
    $mailer->Fromname = $email;
    $mailer->AddAddress($to);
     
    $mailer->Subject = $subject;
    $mailer->Body = $body;
     
    // Check the email address enmtered matches the standard email address format
     if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) { 
      echo "<p></p><p>**It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p></p><p></p><p></p><p></p><p>"; 
    } 
     
     elseif (!trim($name)) { 
      echo "<p></p><p>**It appears that you did not fill out all of the required information.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
    } 
     elseif (!trim($address)) { 
      echo "<p></p><p>**It appears that you did not fill out all of the required information.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
    }    
     elseif (!trim($phone)) { 
      echo "<p></p><p>**It appears that you did not fill out all of the required information.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
    } 
     elseif (!trim($email)) { 
      echo "<p></p><p>**It appears that you did not fill out all of the required information.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
    }
     
    // Sends out the email or will output the error message 
     elseif ($mailer->Send()) { 
      echo "<p></p><p>$name, Thank you for contacting us.</p>"; 
     
    } 
    } 
    else { 
    ?>

  2. #2
    SitePoint Zealot Steveiwonder's Avatar
    Join Date
    Nov 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Each e-mail address must be seperated by a commar (,)

    like

    PHP Code:
    $send_to "example@example.com, john@smiths.com"
    Last edited by Steveiwonder; Mar 19, 2009 at 12:13.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Steveiwonder - thanks for your response.

    I was hoping it was that simple too, but unfortunately it's not. I tried it that way, and the email does not send to the second address.

    Could it have something to do with the script in there that prevents the email from being sent without password authentication? Maybe the email to the second address is being rejected because it's bouncing off of a different mail server with no password verification? And if so, is there any way to have it still send to the second address? I'm stumped...

    Thanks.

  4. #4
    SitePoint Zealot Steveiwonder's Avatar
    Join Date
    Nov 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you able to test this script on a server that doesnt require auth? Just to try and narrow it down?
    Btw.. do you get any error message or bounce back emails?

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good suggestion, I'll work on testing the script on another server. But no, there are no error messages or bounce back emails.

  6. #6
    SitePoint Zealot Steveiwonder's Avatar
    Join Date
    Nov 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no need to repeat your error message from your if statment, unless you plan on outputting individual error messages

    Code PHP:
    // Check the email address enmtered matches the standard email address format
     if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
      echo "<p></p><p>**It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p></p><p></p><p></p><p></p><p>";
    }
     
     elseif (!trim($name) || !trim($address) || !trim($phone) || !trim($email)) {
      echo "<p></p><p>**It appears that you did not fill out all of the required information.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
    }
     
     
    // Sends out the email or will output the error message
     elseif ($mailer->Send()) {
      echo "<p></p><p>$name, Thank you for contacting us.</p>";
     
    }

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steveiwonder View Post
    Are you able to test this script on a server that doesnt require auth? Just to try and narrow it down?
    Btw.. do you get any error message or bounce back emails?
    I tested my script on a server that does not require authentication, and the email is still not being sent to the second address. It seems that whichever address comes before the comma works perfectly, and the address after the comma is essentially being ignored.

    Does anyone know why I can't get this form to send to the second email address?

    FYI, if I remove the password authentication information and test it on a different server, the email sends to both addresses.

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steveiwonder View Post
    There is no need to repeat your error message from your if statment, unless you plan on outputting individual error messages

    Code PHP:
    // Check the email address enmtered matches the standard email address format
     if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
      echo "<p></p><p>**It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p></p><p></p><p></p><p></p><p>";
    }
     
     elseif (!trim($name) || !trim($address) || !trim($phone) || !trim($email)) {
      echo "<p></p><p>**It appears that you did not fill out all of the required information.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
    }
     
     
    // Sends out the email or will output the error message
     elseif ($mailer->Send()) {
      echo "<p></p><p>$name, Thank you for contacting us.</p>";
     
    }
    steveiwonder - thank you for helping to simplify my error code. i went ahead and made that change.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •