• Resolved lazyym

    (@lazyym)


    I’ve tried your contact form snippet and its states outdated and somehow loads someone else plugin when you click update.

    Anyways, how do we customize the contact form to include the ad title in the email subject when someone contacts them about the ad? Maybe even a link to the ad at the site? Or at least a footer we can put a link in?

Viewing 5 replies - 1 through 5 (of 5 total)
  • In my case, i have hid the subject box, and fill it with custom javascript. But if there is an easier way i would be happy to use as well. Just noting here to get notified of Greg’s answer.

    Plugin Author Greg Winiarski

    (@gwin)

    You can add post title in the message title by adding following code to your theme functions.php file

    
    add_filter( "adverts_contact_form_email", "contact_form_email", 10, 3 );
    function contact_form_email( $mail, $post_id, $form ) {
        $post = get_post( $post_id );
        
        $mail["subject"] = $post->post_title . " - " . $mail["subject"];
        return $mail;
    }
    

    The snippets from GitHub you should never update, as they will be replaced with plugins from WordPress.org repository which have the same name.

    Thread Starter lazyym

    (@lazyym)

    Perfect as usual. Woks great! Now, how can I modify that to contain a “Re:” in front of the post title in the subject and a link to the site in the message area? Ideally, a link to the post itself would be great! I hate to be a pain but this is fundamental stuff @gwin. Thank you sir!

    Plugin Author Greg Winiarski

    (@gwin)

    Change the line

    
    $mail["subject"] = $post->post_title . " - " . $mail["subject"];
    

    to

    
    $mail["subject"] = "Re: " . $post->post_title . " - " . $mail["subject"];
    $mail["message"] .= "\r\n---\r\n";
    $mail["message"] .= get_permalink( $post ) . "\r\n";
    

    you will have “Re:” at beggining of the title and link to Advert at the bottom of the message.

    Thread Starter lazyym

    (@lazyym)

    Thanks Greg, so the complete function should be?

    
    add_filter( "adverts_contact_form_email", "contact_form_email", 10, 3 );
    function contact_form_email( $mail, $post_id, $form ) {
        $post = get_post( $post_id );
        
        $mail["subject"] = "Re: " . $post->post_title . " - " . $mail["subject"];
        $mail["message"] .= "\r\n---\r\n";
        $mail["message"] .= get_permalink( $post ) . "\r\n";
        return $mail;
    }

    And it works! Thanks again!

    Now I notice the site email displays as from. But when they click reply, it shows the senders email. Is there a way to display the from senders email in the from line rather than the admin email address?

    I am already getting emails from those who’ve received messages in the admin inbox for my site.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Contact form subject?’ is closed to new replies.