Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

CF7 having a breakline in custom function WordPress

  • SOLVED

I have a WP setup with the plugins ContactForm7 - ContactForm7 Dynamic Text Extension - and WP Favorite Post.

I made a custom Function in the CF7 DTX Extension to have a shortcode that put the urls of the favorites in a CF7 emailbody.

My Problem is that the output of the function is in one line in the email.

e.g. url1url2url3...

should be

url1
url2
url3
.
.

I try to make a Breakline in the function but it look like CF7 rip this from the script ?


my C7 DTX function is (I use custom post types!)

function cf7_favlist(){
$favorite_post_ids = wpfp_get_users_favorites();
if ($favorite_post_ids):
foreach ($favorite_post_ids as $property_id) {
$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));
$fav_post .= $property['permalink'].'</br>'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody
}
else:
$fav_post .= 'favlist is empty.';
endif;
return $fav_post;
}
add_shortcode('CF7_favlist', 'cf7_favlist');



Hope someone can help to get the function output an Breakline that works in the email body.

Answers (5)

2012-01-20

Julio Potier answers:

Hello
Try with '<br />' or "\n" (take care, i wrote " and not ' for the \n ! )

See you !


Peter Brain comments:

i see, the /br tag was a typo but it do not work

$fav_post .= $property['permalink']."/n"; do not work it adds the /n after the url e.g.

url1/nurl2/n...


Julio Potier comments:

Bad, try to enclose with <div> tags
function cf7_favlist(){
$favorite_post_ids = wpfp_get_users_favorites();
if ($favorite_post_ids):
foreach ($favorite_post_ids as $property_id) {
$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));
$fav_post .= '<div>' . $property['permalink'].'</div>';
}
else:
$fav_post .= 'favlist is empty.';
endif;
return $fav_post;
}
add_shortcode('CF7_favlist', 'cf7_favlist');


or use "nl2br" function :
function cf7_favlist(){
$favorite_post_ids = wpfp_get_users_favorites();
if ($favorite_post_ids):
foreach ($favorite_post_ids as $property_id) {
$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));
$fav_post .= $property['permalink'];
}
else:
$fav_post .= 'favlist is empty.';
endif;
return nl2br( $fav_post );
}
add_shortcode('CF7_favlist', 'cf7_favlist');


Peter Brain comments:

the urls will not break this must be a filter in cf7 i guess

2012-01-20

Arnav Joy answers:

try returning this as

function cf7_favlist(){

$favorite_post_ids = wpfp_get_users_favorites();

if ($favorite_post_ids):

foreach ($favorite_post_ids as $property_id) {

$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));

$fav_post .= $property['permalink'].'</br>'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody

}

else:

$fav_post .= 'favlist is empty.';

endif;

return nl2br($fav_post);

}

add_shortcode('CF7_favlist', 'cf7_favlist');


Peter Brain comments:

this do not work, the url's are still in one line


Arnav Joy comments:

ok how you are calling the function ??


Arnav Joy comments:

try this

function cf7_favlist(){

$favorite_post_ids = wpfp_get_users_favorites();

if ($favorite_post_ids):

foreach ($favorite_post_ids as $property_id) {

$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));

$fav_post .= $property['permalink'].'<br />'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody

}

else:

$fav_post .= 'favlist is empty.';

endif;

return nl2br($fav_post);

}

add_shortcode('CF7_favlist', 'cf7_favlist');


Note you used br as </br> in place
of <br />

use my code


Arnav Joy comments:

when you send your email did you checked the header for the html content??

like

$headers= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers.= 'From: from name'. "\r\n" .
'X-Mailer: PHP/' . phpversion();


Arnav Joy comments:

try this you will get that your email is ok with html tags or not

function cf7_favlist(){

$favorite_post_ids = wpfp_get_users_favorites();

if ($favorite_post_ids):
$fav_post ="<table>";
foreach ($favorite_post_ids as $property_id) {

$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));

$fav_post .= '<tr><td>'.$property['permalink'].'</td></tr>'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody

}

else:

$fav_post .= '<tr><td>favlist is empty.</td></tr>';

endif;

$fav_post ="</table>";
return nl2br($fav_post);

}


Peter Brain comments:

i have Content-Type: text/html; charset="UTF-8" don't know if this can be changed in CF7


Arnav Joy comments:

so use my this function you will get html is ok or not

function cf7_favlist(){

$favorite_post_ids = wpfp_get_users_favorites();

if ($favorite_post_ids):
$fav_post ="<table>";
foreach ($favorite_post_ids as $property_id) {

$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));

$fav_post .= '<tr><td>'.$property['permalink'].'</td></tr>'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody

}

else:

$fav_post .= '<tr><td>favlist is empty.</td></tr>';

endif;

$fav_post ="</table>";
return nl2br($fav_post);

}


Arnav Joy comments:

how do you using this function in sending email can you tell or it is automated from this plugin it self..

if you are using wp_mail() or mail() then use it as:--

$mailContent = nl2br($mailContent);

and pass this varible in the message .


Peter Brain comments:

the output in the email body is empy :(


Arnav Joy comments:

try this

function cf7_favlist(){

$favorite_post_ids = wpfp_get_users_favorites();

if ($favorite_post_ids):
$fav_post ="<table>";
foreach ($favorite_post_ids as $property_id) {

$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));

$fav_post .= '<tr><td>'.$property['permalink'].'</td></tr>'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody

}

else:

$fav_post .= '<tr><td>favlist is empty.</td></tr>';

endif;

$fav_post ="</table>";
return $fav_post;

}

2012-01-20

Kannan C answers:

break tags cannot work on emails. You may try \r\n

function cf7_favlist(){
$favorite_post_ids = wpfp_get_users_favorites();
if ($favorite_post_ids):
foreach ($favorite_post_ids as $property_id) {
$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));
$fav_post .= $property['permalink']."\r\n";
}
else:
$fav_post .= 'favlist is empty.';
endif;
return $fav_post;
}

add_shortcode('CF7_favlist', 'cf7_favlist');


Peter Brain comments:

you got it !! Thanx a lot

2012-01-20

rizaljohn answers:

Wrap it with p tag


Peter Brain comments:

i try it before that do no work.


rizaljohn comments:

Please make sure that the email settings accept html tags.


Peter Brain comments:

yes it is, this was the first thing that i try

2012-01-20

Francisco Javier Carazo Gil answers:

Hi Groundcontrol,

Try with two '<br/>' it will rest in this way:

function cf7_favlist(){

$favorite_post_ids = wpfp_get_users_favorites();

if ($favorite_post_ids):

foreach ($favorite_post_ids as $property_id) {

$property = prepare_property_for_display(get_property($property_id, "get_property['children']={$show_property['children']}"));

$fav_post .= $property['permalink'].'<br/><br/>'; // <--------this is the variable for the url the </br> tag is not reconized in the emailbody

}

else:

$fav_post .= 'favlist is empty.';

endif;

return $fav_post;

}

add_shortcode('CF7_favlist', 'cf7_favlist');


Peter Brain comments:

nope, looks like the <br/> is filtered in the emailbody


Francisco Javier Carazo Gil comments:

Hi,

If this is filtered try this CSS: http://www.handycss.com/how/how-to-insert-line-breaks-via-css-without-br-tag/