Page 1 of 1
Problem with Swifmailer and FCKeditor
Posted: Fri Jan 11, 2008 6:04 am
by jefke007
Hello, i'm new with swiftmailer, i want to use fck editor to create a email.
Here is some code i got.
Every thing works fine, only the mail i get isn't good.
Can't see any images.
When i echo $content is get
Code: Select all
<p>Blabla bla</p>
<p><img width=\"500\" height=\"500\" src=\"" . $message->attach(new Swift_Message_Image(new Swift_File("../gfx/image/bureau.JPG" ))) . "\" /></p>
<p>bla bla</p>
<p><img width=\"500\" height=\"500\" src=\"" . $message->attach(new Swift_Message_Image(new Swift_File("../gfx/image/nachtkast.JPG" ))) . "\" /></p>
<p>bla bla bla </p>
If i copy and past the content of $content in the $message-> ... IT works.
I think there is something wrong with the line off
$message->attach(new Swift_Message_Part($content, 'text/html'));
I have tried "$content" '$content' $content
Code: Select all
<?php
function str_replace_all($search,$replace,$subject) {
while(strpos($subject,$search)!==false) {
$subject = str_replace($search,$replace,$subject);
}
return $subject;
}
$string = $_POST['nieuwsbrief'];
$string = addslashes($string);
$content = str_replace_all('src=\"/', 'src=\"" . $message->attach(new Swift_Message_Image(new Swift_File("', $string);
$content = str_replace_all('\" alt=\"\" />', '" ))) . "\" />',$content);
$content = str_replace_all('WIBS', '..',$content);
require_once "mail/Swift.php";
require_once "mail/Swift/Connection/SMTP.php";
$smtp =& new Swift_Connection_SMTP("uit.pandora.be", 25);
$swift =& new Swift($smtp);
$message =& new Swift_Message("Your subject");
echo $content ;
$message->attach(new Swift_Message_Part($content, 'text/html'));
if ($swift->send($message, new Swift_Address("jefke007@gmail.com", "Joe"), new Swift_Address("jefke007@gmail.com", "System")))
{
echo "Message sent";
}
else
{
echo "Sending failed";
}
//recommended to do this
$swift->disconnect();
?>
Can sombody help me with this? How to put a variable in to swift body ?
Thanks
Greatzz jefke007
Re: Problem with Swifmailer and FCKeditor
Posted: Fri Jan 11, 2008 6:32 pm
by Chris Corbyn
Code: Select all
$content = str_replace_all('src=\"/', 'src=\"" . $message->attach(new Swift_Message_Image(new Swift_File("', $string);
Check your use of backslashes, singe and double quotes here. I'd suggest using an editor which does syntax highlighting if not already since this would stick out like a sore thumb in that case
EDIT | In fact, what you're trying to do isn't going to work at all. PHP isn't markup so you can't just replace HTML with PHP and email it. You need a preg_replace() to get this to work.
Code: Select all
function attachImage($matches) {
global $message; //this isn't great but I don't know enough about your code
return 'src="' . $message->attach(new Swift_Message_Image(new swift_File($matches[1]))) . '"';
}
$content = preg_replace_callback('~src="([^"]*)"~', 'attachImage', $string);
Re: Problem with Swifmailer and FCKeditor
Posted: Sat Jan 12, 2008 4:08 pm
by jefke007
Isn't working for me.
Alle the text in $content is fine, but the problem is that the content of $content isn't handled as HTML.
when i do
$content = "<p> testing 1234 </p>" ;
I get a good email, but when i use
$content ='<img width=500 height=500 src=\"" . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) ."\"/>';
I get a white image and attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) ."\"/>
I tested
$message->attach(new Swift_Message_Part($content, 'text/html'));
and
$message->attach(new Swift_Message_Part($content));
In al me emails i get the code op $content. So the content in $content isn't handled by $message...
here is the code. I changed is so you can test it.
Code: Select all
<?php
/*
function str_replace_all($search,$replace,$subject) {
while(strpos($subject,$search)!==false) {
$subject = str_replace($search,$replace,$subject);
}
return $subject;
}
$string = $_POST['nieuwsbrief'];
function attachImage($matches) {
global $message; //this isn't great but I don't know enough about your code
return 'src=\"" . $message->attach(new Swift_Message_Image(new swift_File("'.$matches[1].'"))) ."\"';
}
$content = preg_replace_callback('~src="([^"]*)"~', 'attachImage', $string);
$content = str_replace_all('/WIBS', '..',$content);
echo ($content);
*/
$content ='<img width=500 height=500 src=\"" . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) ."\"/>';
require_once "mail/Swift.php";
require_once "mail/Swift/Connection/SMTP.php";
$smtp =& new Swift_Connection_SMTP("uit.pandora.be", 25);
$swift =& new Swift($smtp);
$message =& new Swift_Message("Your subject");
$message->attach(new Swift_Message_Part($content,"text/html"));
//$message->attach(new Swift_Message_Part("<img width=500 height=500 src=\"" . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) ."\" />","text/html"));
/*
$message->attach(new Swift_Message_Part("<p>fhffhfhhf</p>
<p>sdsds</p>
<p><img width="500" height="500" src=\"" . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) ."\" alt="" /></p>, "text/html"));
*/
if ($swift->send($message, new Swift_Address("jefke007@gmail.com", "Joe"), new Swift_Address("jefke007@gmail.com", "System")))
{
echo "Message sent";
}
else
{
echo "Sending failed";
}
//recommended to do this
$swift->disconnect();
?>
Thanks
got any idea?
Thank u
Re: Problem with Swifmailer and FCKeditor
Posted: Sat Jan 12, 2008 10:24 pm
by Chris Corbyn
Same problem. I've highlighted your code for you to have a closer look. Particularly this:
Code: Select all
$content ='<img width=500 height=500 src=\"" . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) ."\"/>';
require_once "mail/Swift.php";
require_once "mail/Swift/Connection/SMTP.php";
Red syntax indicates that it's a string. $message->attach(... yadda yadda is just a plain old string in your code and thus is not being interpreted as PHP. This is what I was trying to say the first time around.
Re: Problem with Swifmailer and FCKeditor
Posted: Sun Jan 13, 2008 2:47 am
by jefke007
is there any way to get is interpreted as PHP??
Maybe i can create a php file with this code and send the php file?
thank u
Re: Problem with Swifmailer and FCKeditor
Posted: Sun Jan 13, 2008 2:55 am
by Weirdan
jefke007 wrote:is there any way to get is interpreted as PHP??
thank u
get it out of the string, like this:
Code: Select all
$content ='<img width=500 height=500 src="' . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) .'"/>';
Re: Problem with Swifmailer and FCKeditor
Posted: Sun Jan 13, 2008 2:56 am
by Chris Corbyn
jefke007 wrote:is there any way to get is interpreted as PHP??
thank u
Yes, fix the wrong use of double quotes. You open your string with single quotes, then *try* to get out of the string by using souble quotes followed by . (dot). You need to get out of the string the same way you got into the string.
Code: Select all
$content ='<img width=500 height=500 src="' . $message->attach(new Swift_Message_Image(new swift_File("../gfx/image/bureau.JPG"))) .'"/>';
require_once "mail/Swift.php";
require_once "mail/Swift/Connection/SMTP.php";
Re: Problem with Swifmailer and FCKeditor
Posted: Sun Jan 13, 2008 5:17 pm
by jefke007
isn't working for me, i get error :p
Fatal error: Call to a member function attach() on a non-object in C:\wamp\www\WIBS\admin\module_massmail_mail.php on line 17
i'm traing to change the " and the \ and so on but isn't working
Thanks for all the help in advance
Re: Problem with Swifmailer and FCKeditor
Posted: Sun Jan 13, 2008 5:55 pm
by jefke007
I GOT IT WORKING :p:p:p:p:p:p:p
$string = str_replace_all("/WIBS", '..',$string);
function attachImage($matches) {
global $message; //this isn't great but I don't know enough about your code
return "src=\"". $message->attach(new Swift_Message_Image(new swift_File("$matches[1]")))."\" ";
}
require_once "mail/Swift.php";
require_once "mail/Swift/Connection/SMTP.php";
$smtp =& new Swift_Connection_SMTP("uit.pandora.be", 25);
$swift =& new Swift($smtp);
$message =& new Swift_Message("Your subject");
$content = preg_replace_callback('~src="([^"]*)"~', 'attachImage', $string);
THANKS, So if somebody wants this script
So now u can use fck editor to create a email with image and tekst.