[SOLVED] inline images

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
phobos
Forum Newbie
Posts: 3
Joined: Wed Feb 28, 2007 8:35 am

[SOLVED] inline images

Post by phobos »

Hi, I've been using Swift for last 2 months to control e-mail traffic on my website and I'd like to do some e-mail info action. In order to do this I'd like to sent some messages with an image inline just the way spammers do. Here's the snippet of code I'm using (it's Swift version 2, I don't have time to migrate to version 3 now)

Code: Select all

$email = $this->emailContent; // get the template

// some manipulation with content - insert name, current date and then

$mailer = new Swift(new Swift_Connection_SMTP($address));

$cid = $mailer->addImage($this->config['image_file']);
$email = mb_eregi_replace('image_name', $cid, $email);

if ($mailer->authenticate($user, $pass) {
  $mailer->send($toAddress, $address, 'test', $email);
} 
else echo 'mailer failed to connect';
$mailer->close();
As you can guess, my email template contains part
<img src="image_name" style="some_style_over_here"/>
And the problem is that my image isn't even attached to e-mail at all! Should I do anything more? I thought that simple addImage method will be OK.

Thanks in advance
phobos
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

This post didn't seem applicable to the tutorial thread it was posted in, so it's been split.
phobos
Forum Newbie
Posts: 3
Joined: Wed Feb 28, 2007 8:35 am

Post by phobos »

Sorry for misplacing the post. I forgot to mention that var_dump($mailer) just before send(...) says that image is attached. And it still is not displayed in any client.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Don't pass the message body to send() in v2. Use addPart() instead if you are adding attachments or images.

Code: Select all

$email = $this->emailContent; // get the template 

// some manipulation with content - insert name, current date and then 

$mailer = new Swift(new Swift_Connection_SMTP($address)); 

$cid = $mailer->addImage($this->config['image_file']); 
$email = mb_eregi_replace('image_name', $cid, $email); 
$mailer->addPart($email, "text/html");

if ($mailer->authenticate($user, $pass) { 
  $mailer->send($toAddress, $address, 'test'); 
} 
else echo 'mailer failed to connect'; 
$mailer->close();
phobos
Forum Newbie
Posts: 3
Joined: Wed Feb 28, 2007 8:35 am

Post by phobos »

Thanks! That did the job. Another thing is - if I sometimes get to 'mailer failed to connect' part, what could it be? I send two mails from one account OK, but third one fails... or sometimes first one fails but the second one goes away.
Post Reply