Embedding the image
Posted: Fri Dec 05, 2008 6:54 am
Below I have a PHP script that works perfectly. The problem starts when I set the variable $body_text to read the HTML code from the Db and the picture is no longer attached but set <img src exactly to the Swift function call. The script runs every five minutes to send emails where the HTML code is read from the Db. Any help.
<?php
require_once "../../include/lib/Swift.php";
require_once "../../include/lib/Swift/Connection/SMTP.php";
$smtp = new Swift_Connection_SMTP("mail.mymail.co.za", 25);
$swift = new Swift($smtp);
$message = new Swift_Message("My Swift Test");
$path = "C:/Data/pics/";
$body_text =
"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>Test Swift</title>
</head>
<body>
<p>This is my test picture <img src='" . $message->attach(new Swift_Message_Image(new Swift_File($path
. "mypic.jpg"))) . "'> that does not show when the HTML code is read from the Db.</p>
</body>
</html>";
$sname = "My Company";
$webmaster = "webmaster@mymail.co.za");
$email = "me@mymail.co.za";
$message->attach(new Swift_Message_Part($body_text, "text/html"));
if($swift->send($message,new Swift_Address($email),new Swift_Address($webmaster, $sname)))
echo "email sent to: $email.";
else
echo "failed email sending to: $email.";
?>
<?php
require_once "../../include/lib/Swift.php";
require_once "../../include/lib/Swift/Connection/SMTP.php";
$smtp = new Swift_Connection_SMTP("mail.mymail.co.za", 25);
$swift = new Swift($smtp);
$message = new Swift_Message("My Swift Test");
$path = "C:/Data/pics/";
$body_text =
"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>Test Swift</title>
</head>
<body>
<p>This is my test picture <img src='" . $message->attach(new Swift_Message_Image(new Swift_File($path
. "mypic.jpg"))) . "'> that does not show when the HTML code is read from the Db.</p>
</body>
</html>";
$sname = "My Company";
$webmaster = "webmaster@mymail.co.za");
$email = "me@mymail.co.za";
$message->attach(new Swift_Message_Part($body_text, "text/html"));
if($swift->send($message,new Swift_Address($email),new Swift_Address($webmaster, $sname)))
echo "email sent to: $email.";
else
echo "failed email sending to: $email.";
?>