#1
  1. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,108
    Rep Power
    143

    need help with HTML emails


    Hi--

    I have a client who needs to send HTML-formatted emails with inline images.It's basically a newsletter.

    So far, I've got an instance of tinyMCE running to generate the HTML and that content goes to phpMailer. For the most part that works fine except for inline images.

    Trying to following the docs for phpMailer here: Worx International Inc.

    I'm basically replacing the src attribute with cid:name and using the AddEmbeddedImage function.

    So, when I send the email, phpMailer receives this:

    Code:
    <p><img src="http://site.com/images/images/blobid1491421613414.jpg" alt="" width="500" height="200" /></p>
    <p>this is the <strong>body text</strong>.</p>
    and I change it to this:

    Code:
    <p><img src="cid:attach1" alt="" width="500" height="200" /></p>
    <p>this is the <strong>body text</strong>.</p>
    I'm stripping the full http path, replacing it with the cid info and using this in my code when building the message:

    Code:
    $mail->AddEmbeddedImage($filepath, "attach1", $filepath);
    As I said, the message comes through fine, the text is bolded, but it's missing the image.

    Does anyone have experience with this?

    Thank you!
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  2. #2
  3. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,108
    Rep Power
    143
    it did work, but now it's not again...
    Last edited by Frank Grimes; April 6th, 2017 at 10:39 AM.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  4. #3
  5. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,108
    Rep Power
    143
    Okay, it's not working again.

    Same situation as above...I'm generating this code from tinyMCE:

    Code:
    <p><img src="http://site.com/images/blobid1491425164932.jpg" alt="" width="500" height="200" /></p>
    <p>sdjlsajf</p>
    <p><img src="http://site.com/images/blobid1491425172951.jpg" alt="" width="500" height="500" /></p>
    Converting it to this:

    Code:
    <p><img src="cid:attach1" alt="" width="500" height="200" /></p>
    <p>sdjlsajf</p>
    <p><img src="cid:attach2" alt="" width="500" height="500" /></p>
    embedding the images this way:

    Code:
    $mail->AddEmbeddedImage("http://site.com/images/blobid1491425164932.jpg", "attach1", "http://site.com/images/blobid1491425164932.jpg");
    $mail->AddEmbeddedImage("http://site.com/images/blobid1491425172951.jpg", "attach2", "http://site.com/images/blobid1491425172951.jpg");
    Sending the message, the text comes through fine, but no images.

    here's my full code:

    Code:
    $m=$_POST['m'];
    
    	require 'phpmailer/PHPMailerAutoload.php';
    	$mail = new PHPMailer;
    
    	$broken=explode("src=\"",$m);
    
    	for ($i=0;$i<count($broken);$i++) {
    		if (substr($broken[$i],0,4)=="http") {
    			$e=strpos($broken[$i],".jpg");
    			$e+=4;
    			$file=substr($broken[$i],0,$e);
    
    			$broken[$i]=str_replace($file,"cid:attach".$i,$broken[$i]);
    			$mail->AddEmbeddedImage($file, "attach".$i, $file);
    		}
    	}
    
    	$message=implode("src=\"",$broken);sendin	
    	
    	$mail->setFrom('me@me.com', 'grimey');
    	$mail->addAddress('some@jerk.com', 'guy');     // Add a recipient
    	
    
    	$mail->Subject = 'Testing new mailer';
    	$mail->Body    = $message;
    	$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    	$mail->isHTML(true);
    
    	if(!$mail->send()) {
    	    echo 'Message could not be sent.';
    	    echo 'Mailer Error: ' . $mail->ErrorInfo;
    	} else {
    	    echo 'Message has been sent';
    	}
    For real this time, can anyone help?
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  6. #4
  7. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,971
    Rep Power
    9615
    What's the full source of the email as received, minus the headers? (If there's anything sensitive be sure to put in something fake instead.)
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,457
    Rep Power
    1874
    Originally Posted by Frank Grimes
    it did work, but now it's not again...

    This is a sure sign it's time to investigate the use of a revision control system such as git / cvs / svn / more.

    Every time something works, or other progress is made, you make a commit so you always have some known point to go back to.

    One immediately useful feature is the ability to 'diff' between commits to find out exactly what you did to make/break your latest effort.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo