Forums

Email from SubmitContent form

jbudd 22 Mar, 2009
The email template from the SubmitContent form looks like this:
<p>Hi,</p>
<p>New user has submitted a new Content item, please review it!</p>
<p><strong>Title:</strong>{title}</p>
<p><strong>Body:</strong> {fulltext}</p>


If the user included a picture in their content item the URL will be a relative one like this:
<img src="images/stories/jbudd/blacksheep.gif">


And obviously the picture doesnt show up in the email.

Is there any way to change URLs in the email only to absolute ones like
<img src="http://mysite/images/stories/jbudd/blacksheep.gif">


I guess this would have to be some sort of mambot / plugin?
GreyHead 22 Mar, 2009
Hi jbudd,

The image links are in the $attachments array so you could change them in the OnSubmit Before box to add the site prefix. It woudl be something like
<?php
foreach ( $attachment as $k => $image ) {
  $attachment[$k] = JURI::base().$image;
}
?>
I'm not sure I've got the slashes correct but you can fix that.

Bob
jbudd 22 Mar, 2009
Thanks for such a quick response Greybeard. Glad to see I'm not the only one working on Sunday :wink:

I put this in the Before Email code
<?php
foreach ( $attachments as $k => $image ) {
  $attachments[$k] = JURI::base().$image;
}
?>


I would expect it to change the attachment URL in the content item - fair enough, I can strip the URLs in the After Email code...
but in fact it doesnt seem to do anything.

I presume that my images are not in $attachments.

Here is a real example of the item contents:
<p>Testing Testing</p><img alt="blacksheep" src="images/stories/jbudd/blacksheep.gif" width="290" height="300" />


One way to do it might be to add a function to the email code ie
<p>Hi,</p>
<p>New user has submitted a new Content item, please review it!</p>
<p><strong>Title:</strong>{title}</p>
<p><strong>Body:</strong> <?php longimagesrc($_POST['fulltext']) ?></p>

but where do I define the longimagesrc() function?
jbudd 22 Mar, 2009
Well I tried this email template:
<p>Hello admin,</p>
    <p>{username} has submitted a Year 6 News item, please review and publish it!</p>
    <p><strong>Title:</strong>{title}</p>
    <p><strong>Body:</strong> <php? echo preg_replace('src="images/stories', 'src="mysite/images/stories', Jrequest::getVar('introtext'); ?></p>

and the email is blank after Body:

More experiments needed....
GreyHead 22 Mar, 2009
Hi Jbudd,

Just spotted <php? - should be <?php . . . and you are correct, it should be $attachments (plural) not $attachment as I wrote it.

Bob
jbudd 22 Mar, 2009

Just spotted <php? - should be <?php



Hmm, i made lots of dumb errors in that tiny bit of code!

Thanks again.
This topic is locked and no more replies can be posted.