Results 1 to 2 of 2

Thread: contact email - send carbon copy to user

  1. #1
    Thread Starter
    cyberpaul's Avatar
    Join Date
    Jul 2011
    Location
    Germany
    Posts
    95
    Thanks
    8
    Thanked 2 Times in 2 Posts

    contact email - send carbon copy to user

    Hi there,

    the users of my platform like to receive a carbon copy of the mail they are sending out to an ad owner. So I added a checkbox in /includes/sidebar-contact.php with the following line:

    Code:
    <li>Like to receive a copy of the mail?  <input type="checkbox" name="sendcc" value="true" checked></li>
    That was the easy part. Now I know that i have to modify the file /includes/emails.php in there is the function: cp_contact_ad_owner_email

    To use the cc tag, I used the header of the mail and i replaced the line "wp_mail( $email['to'], $email['subject'], $email['message'] );" with this:

    Code:
    if (strip_tags($_POST['sendcc']) == true) {
      $headers = 'Cc: $from_email \r\n'; 
      wp_mail( $mailto, $subject, $message , $headers);
    } else  wp_mail( $email['to'], $email['subject'], $email['message'] );
    so the function looks like this:

    Code:
    // ad poster sidebar contact form email
    function cp_contact_ad_owner_email( $post_id ) {
    	$errors = new WP_Error();
    
    	// check for required post data
    	$expected = array( 'from_name', 'from_email', 'subject', 'message' );
    	foreach ( $expected as $field_name ) {
    		if ( empty( $_POST[ $field_name ] ) ) {
    			$errors->add( 'empty_field', __( 'ERROR: All fields are required.', APP_TD ) );
    			return $errors;
    		}
    	}
    
    	// check for required anti-spam post data
    	$expected_numbers = array( 'rand_total', 'rand_num', 'rand_num2' );
    	foreach ( $expected_numbers as $field_name ) {
    		if ( ! isset( $_POST[ $field_name ] ) || ! is_numeric( $_POST[ $field_name ] ) ) {
    			$errors->add( 'invalid_captcha', __( 'ERROR: Incorrect captcha answer.', APP_TD ) );
    			return $errors;
    		}
    	}
    
    	// verify captcha answer
    	$rand_post_total = (int) $_POST['rand_total'];
    	$rand_total = (int) $_POST['rand_num'] + (int) $_POST['rand_num2'];
    	if ( $rand_total != $rand_post_total )
    		$errors->add( 'invalid_captcha', __( 'ERROR: Incorrect captcha answer.', APP_TD ) );
    
    	// verify email
    	if ( ! is_email( $_POST['from_email'] ) )
    		$errors->add( 'invalid_email', __( 'ERROR: Incorrect email address.', APP_TD ) );
    
    	// verify post
    	$post = get_post( $post_id );
    	if ( ! $post )
    		$errors->add( 'invalid_post', __( 'ERROR: Ad does not exist.', APP_TD ) );
    
    	if ( $errors->get_error_code() )
    		return $errors;
    
    	$mailto = get_the_author_meta( 'user_email', $post->post_author );
    
    	$from_name = appthemes_filter( appthemes_clean( $_POST['from_name'] ) );
    	$from_email = appthemes_clean( $_POST['from_email'] );
    	$subject = appthemes_filter( appthemes_clean( $_POST['subject'] ) );
    	$posted_message = appthemes_filter( appthemes_clean( $_POST['message'] ) );
    
    	$sitename = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES );
    	$siteurl = home_url('/');
    	$permalink = get_permalink( $post_id );
    
    	$message = sprintf( __( 'Someone is interested in your ad listing: %s', APP_TD ), $permalink ) . "\r\n\r\n";
    	$message .= '"' . wordwrap( $posted_message, 70 ) . '"' . "\r\n\r\n";
    	$message .= sprintf( __( 'Name: %s', APP_TD ), $from_name ) . "\r\n";
    	$message .= sprintf( __( 'E-mail: %s', APP_TD ), $from_email ) . "\r\n\r\n";
    	$message .= '-----------------------------------------' . "\r\n";
    	$message .= sprintf( __( 'This message was sent from %s', APP_TD ), $sitename ) . "\r\n";
    	$message .=  $siteurl . "\r\n\r\n";
    
    
    
    	$email = array( 'to' => $mailto, 'subject' => $subject, 'message' => $message, 'from' => $from_email, 'from_name' => $from_name );
    	$email = apply_filters( 'cp_email_user_ad_contact', $email, $post_id );
    
    	APP_Mail_From::apply_once( array( 'email' => $email['from'], 'name' => $email['from_name'], 'reply' => true ) );
    
    if (strip_tags($_POST['sendcc']) == true) {
      $headers = 'Cc: $from_email \r\n'; 
      wp_mail( $mailto, $subject, $message , $headers);
    } else  wp_mail( $email['to'], $email['subject'], $email['message'] );
    
    	return $errors;
    }
    But this is not working, can anybody help me, please?

  2. #2
    gidantrip's Avatar
    Join Date
    Jun 2014
    Location
    Italy
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. New User Email Plugin in 3.02 BUG - Send Notification Email
    By zontor in forum ClassiPress General Discussion
    Replies: 15
    Last Post: December 25th, 2013, 11:23 AM
  2. filtering email address to send from sidebar-contact
    By guilleush in forum ClassiPress General Discussion
    Replies: 0
    Last Post: August 20th, 2013, 04:27 PM
  3. Google Maps wont send Contact email!! HELP!
    By tlexington in forum Report ClassiPress Bugs
    Replies: 1
    Last Post: November 7th, 2011, 12:53 AM
  4. [MOD NEEDED] Any idea how to change contact-side bar to send an sms instead of an email?
    By toastcard in forum ClassiPress General Discussion
    Replies: 2
    Last Post: January 29th, 2011, 12:49 PM