Help with embedded image
Posted: Tue Feb 05, 2008 3:49 am
Hi
I am trying to send an email with plain text, HTML text, an embedded image and an attachment.
Ignoring the plain text version of the email, I wish the embedded graphic to be at the top of the email, then the HTML text, and then have 1 attachment which can show at the bottom if the client email program has the option set to show attachments.
When I send the email without the final attachment the "header" graphic appears at the top of the HTML text only, great. However if I then add the final attachment the header graphic not only appears at the top but at the bottom too, along with the other attachment.
I do not know if this is a coding issue or whether the email client is being told to perform this way and is normal.
I am using the following code:
// Open new connection
$swift=new Swift(new Swift_Connection_SMTP('127.0.0.1',25));
// Setup message subject
$message=new Swift_Message("$subject_of_email");
// Add PLAIN TEXT data
$message->attach(new Swift_Message_Part("$body_of_email_plain"));
// Convert text to HTML format for the Line Breaks
$body_of_email_html=nl2br($body_of_email_html);
// Add header graphic
$img=new Swift_Message_Image(new Swift_File("../path/"."$graphic_id".".jpg"));
$src=$message->attach($img);
// Add Header Graphic and HTML version of text
$message->attach(new Swift_Message_Part("<img src=\"".$src."\"><br><br>$body_of_email_html","text/html"));
// Attach document to the email
$message->attach(new Swift_Message_Attachment(new Swift_File($path_to_use),"$fileatt_name","application/pdf"));
// Create empty Recipient list
$recipients=new Swift_RecipientList();
// Add recipient including a nice name
$recipients->addTo("$the_client_email","$the_client_name $the_client_surname");
// Send email to customer
$swift->send($message, $recipients, new Swift_Address($from_reply_address,"$nice_name"));
// Close the connection
$swift->disconnect();
I am trying to send an email with plain text, HTML text, an embedded image and an attachment.
Ignoring the plain text version of the email, I wish the embedded graphic to be at the top of the email, then the HTML text, and then have 1 attachment which can show at the bottom if the client email program has the option set to show attachments.
When I send the email without the final attachment the "header" graphic appears at the top of the HTML text only, great. However if I then add the final attachment the header graphic not only appears at the top but at the bottom too, along with the other attachment.
I do not know if this is a coding issue or whether the email client is being told to perform this way and is normal.
I am using the following code:
// Open new connection
$swift=new Swift(new Swift_Connection_SMTP('127.0.0.1',25));
// Setup message subject
$message=new Swift_Message("$subject_of_email");
// Add PLAIN TEXT data
$message->attach(new Swift_Message_Part("$body_of_email_plain"));
// Convert text to HTML format for the Line Breaks
$body_of_email_html=nl2br($body_of_email_html);
// Add header graphic
$img=new Swift_Message_Image(new Swift_File("../path/"."$graphic_id".".jpg"));
$src=$message->attach($img);
// Add Header Graphic and HTML version of text
$message->attach(new Swift_Message_Part("<img src=\"".$src."\"><br><br>$body_of_email_html","text/html"));
// Attach document to the email
$message->attach(new Swift_Message_Attachment(new Swift_File($path_to_use),"$fileatt_name","application/pdf"));
// Create empty Recipient list
$recipients=new Swift_RecipientList();
// Add recipient including a nice name
$recipients->addTo("$the_client_email","$the_client_name $the_client_surname");
// Send email to customer
$swift->send($message, $recipients, new Swift_Address($from_reply_address,"$nice_name"));
// Close the connection
$swift->disconnect();