Add second recipient to email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    Add second recipient to email

    Hi, I have this php email code that works fine but I want to add a second recipient to emails. I tried adding it here but it didnt work

    "CONTACT_FO RM", 'contact@mysite .co.uk' , 'secondemail@ho tmail.com'


    Code:
    <?php
    
    // Where will you get the forms' results?
    define("CONTACT_FORM", 'contact@mysite.co.uk');
    ?>
    Code:
    <?php
    
    include dirname(dirname(__FILE__)).'/mail.php';
    
    error_reporting (E_ALL ^ E_NOTICE);
    
    $post = (!empty($_POST)) ? true : false;
    
    if($post)
    {
    include 'email_validation.php';
    
    $name = stripslashes($_POST['name']);
    $email = trim($_POST['email']);
    $subject = stripslashes($_POST['subject']);
    $message = stripslashes($_POST['message']);
    
    
    $error = '';
    
    // Check name
    
    if(!$name)
    {
    $error .= 'Please enter your name.<br />';
    }
    
    // Check email
    
    if(!$email)
    {
    $error .= 'Please enter an e-mail address.<br />';
    }
    
    if($email && !ValidateEmail($email))
    {
    $error .= 'Please enter a valid e-mail address.<br />';
    }
    
    // Check message (length)
    
    if(!$message || strlen($message) < 10)
    {
    $error .= "Please enter your message. It should have at least 10 characters.<br />";
    }
    
    
    if(!$error)
    {
    $mail = mail(CONTACT_FORM, $subject, $message,
         "From: ".$name." <".$email.">\r\n"
        ."Reply-To: ".$email."\r\n"
        ."X-Mailer: PHP/" . phpversion());
    
    
    if($mail)
    {
    echo 'OK';
    }
    
    }
    else
    {
    echo '<div class="notification_error">'.$error.'</div>';
    }
    
    }
    ?>
    Any ideas would be great.
    Thanks in advance
    Richard
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    try:
    Code:
    define("CONTACT_FORM", 'contact@mysite.co.uk, secondemail@hotmail.com');

    Comment

    • fran7
      New Member
      • Jul 2006
      • 229

      #3
      Hi, Thanks for the reply. I tried that but got the error. email not on server. I am trying to get it to redirect to a second email not on the server. Perhaps I should have specified that.
      Thanks again
      Richard

      Comment

      • Exequiel
        Contributor
        • Jul 2012
        • 288

        #4
        if there are 2 or more recipients you can loop the part where you will send your email. you can put arrays for emails and loop that.

        Comment

        Working...