WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Contact Form 7] Title of the post/page as the subject (1 post)

  1. omidb
    Member
    Posted 4 years ago #

    Hey everyone,

    I'm trying to add a little bit of code to the mail function so the subject of the emails become the title of the post/page which the contact form was placed in. cool isn't it. the modified function looks like this
    --------------------------------------------------------------------
    function compose_and_send_mail($mail_template, $attachments = array()) {
    $regex = '/\[\s*([a-zA-Z][0-9a-zA-Z:._-]*)\s*\]/';
    $callback = array(&$this, 'mail_callback');

    $tryit_out = 7;
    $post_id_7 = get_post($tryit_out);
    $omid = $post_id_7->post_title;
    $mail_subject = preg_replace_callback($regex, $callback, $omid);
    $mail_sender = preg_replace_callback($regex, $callback, $mail_template['sender']);
    $mail_body = preg_replace_callback($regex, $callback, $mail_template['body']);
    $mail_recipient = preg_replace_callback($regex, $callback, $mail_template['recipient']);
    $mail_headers = "From: $mail_sender\n";

    if ($mail_template['use_html'])
    $mail_headers .= "Content-Type: text/html\n";

    if ($attachments) {
    $for_this_mail = array();
    foreach ($attachments as $name => $path) {
    if (false === strpos($mail_template['attachments'], "[${name}]"))
    continue;
    $for_this_mail[] = $path;
    }
    ----------------------------------------------------------------

    I thought it would be simple to detect the post/page id but for some reason the get_id(); does not do the job here. this contact form is place inside a comment and i assume get_id(); is only used inside a loop. any help would be great

Topic Closed

This topic has been closed to new replies.

About this Topic