SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: php email help

  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php email help

    Hi

    I have a html contact form in my website and it's action is using a php file and I am trying to get the contact form to send a email to two different email addresses but can't get it working correctly

    The php file coding the contact form is using is below

    PHP Code:
    <?php  


    // EDIT THE 2 LINES BELOW AS REQUIRED 


    $send_email_to "sales@bhwebsites.co.uk"
    $ccemail "sales@irhwebsites.co.uk"
    $email_subject "Enquiry from the website"


    function 
    send_email($name,$email,$email_message

      global 
    $send_email_to
    global 
    $ccemail
      global 
    $email_subject


      
    $headers "MIME-Version: 1.0" "\r\n"
      
    $headers .= "Content-type:text/html;charset=iso-8859-1" "\r\n"
      
    $headers .= "From: ".$email"\r\n"
    $headers .= "Cc: ".$ccemail"\r\n"


      
    $message "<strong>Email = </strong>".$email."<br>"
      
    $message .= "<strong>Name = </strong>".$name."<br>"
      
    $message .= "<strong>Message = </strong>".$email_message."<br>"
      @
    mail($send_email_to$ccemail$email_subject$message,$headers); 
      return 
    true



    function 
    validate($name,$email,$message

      
    $return_array = array(); 
      
    $return_array['success'] = '1'
      
    $return_array['name_msg'] = ''
      
    $return_array['email_msg'] = ''
      
    $return_array['message_msg'] = ''


     if(
    $email == ''
      { 
            
    $return_array['success'] = '0'
            
    $return_array['email_msg'] = 'email is required'
      } 
      else 
      { 
            
    $email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'
            if(!
    preg_match($email_exp,$email)) { 
              
    $return_array['success'] = '0'
              
    $return_array['email_msg'] = 'enter valid email.';   
            } 
      } 


      if(
    $name == ''
      { 
            
    $return_array['success'] = '0'
            
    $return_array['name_msg'] = 'name is required'
      } 
      else 
      { 
             
    $string_exp "/^[A-Za-z .'-]+$/"
            if (!
    preg_match($string_exp$name)) { 
              
    $return_array['success'] = '0'
             
    $return_array['name_msg'] = 'enter valid name.'
            } 
      } 



      if(
    $message == ''
      { 
            
    $return_array['success'] = '0'
            
    $return_array['message_msg'] = 'message is required'
      } 
      else 
      { 
            if (
    strlen($message) < 2) { 
              
    $return_array['success'] = '0'
              
    $return_array['message_msg'] = 'enter valid message.'
            } 
      } 
      return 
    $return_array



    $name $_POST['name']; 
    $email $_POST['email']; 
    $message $_POST['message']; 



    $return_array validate($name,$email,$message); 
    if(
    $return_array['success'] == '1'

      
    send_email($name,$email,$message); 



    header('Content-type: text/json'); 
    echo 
    json_encode($return_array); 
    die(); 


    ?>

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,167
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    Hi ianhaney, Welcome to the forums.

    You can't add extra bits into the mail() function. See if the answer at the end of this thread from a few days ago helps at all:

    http://www.sitepoint.com/forums/show...023-Email-Form

  3. #3
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,099
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    three things,
    PHP Code:
    global $send_email_to;  
    global 
    $ccemail;  
    global 
    $email_subject;  

    change to 
    global $send_email_to$ccemail$email_subject
    Remove the @ before mail, that suppresses error messages that you may want for debugging.

    call the function directly

    PHP Code:
    $name 'me';
    $email 'me@me.com';
    $email_message 'Hello world';
    send_email($name,$email,$email_message); 
    That should get you going in the right direction.
    What I lack in acuracy I make up for in misteaks


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
  •