dbair Posted January 17, 2008 Share Posted January 17, 2008 I have searched the forums and still have not found an answer. Problem: When sending an html formatted email created using php mail and mime 1) the receiving client (Outlook) shows the text only version by default, 2) the html version is an attachment to the text version and does not show all images. <?php require_once('Mail.php'); require_once('Mail/mime.php'); // use \r\n if using smtp and \n if using mail as factory type. $eMsg = new Mail_mime("\n"); // posted values $uID = $_POST['uID']; list($fname, $eAdd) = split("\|", $myUserEmail[$uID], 2); $to = $eAdd . ", someone@somewhere.com"; $eSubj = ms($_POST['eSubj']); $eAttach = $_POST['eAttach']; // dir/name to attachment $eAttType = $_POST['eAttType']; // mime type of attachment $eImg = $_POST['eImg']; // dir/name of embedded image $imgTp = $_POST['imgTp']; // mime type of embedded image $imgPos = $_POST['imgPos']; // bfr or aftr $eBody = $_POST['eBody']; // if attachment is included, add it to the email if ($eAttach) { $retVal = $eMsg->addAttachment($eAttach, $eAttType, $eAttach, true, 'base64', 'attachment'); if (PEAR::isError($retVal)) { $myMsg = $tst_uname . "|$_SERVER[sCRIPT_NAME] addAttachment failed with error:|" . $retVal->getMessage() . "|" . $create_date . "\n"; logIt($myMsg); print "<script type='text/javascript'>alert('Failed to add attachment to email! Email NOT sent! ');window.location='tst.php';</script>\n"; exit; } } // text only email $emailTxt = "$fname,\n\n" . str_replace("<br />", "\n", $eBody) . "\n\n$txtSig\n"; // html email $logo = file_get_contents("images/emailLogo.jpg"); // $logo = "images/emailLogo.jpg"; $param = array('html_encoding' => 'base64'); $eMsg->get($param); $html = "<html><head><meta http-equiv='Content-Language' content='en' />\n<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />\n<title>$eSubj</title></head>\n<body bgcolor='#FFFFFF' text='#000000' link='#FF9966' vlink='#FF9966' alink='#FFCC99'>\n"; $html .= "<center><a href='http://yoruSite.net/'><img src='images/emailLogo.jpg' /></a></center>\n"; $html .= "<br />$fname,\n"; if ($eImg && $imgPos == "bfr") { $html .= "<br /><img src='$eImg' align='center' />\n"; $html .= "<br />$eBody\n"; } elseif ($eImg && $imgPos == "aftr") { $html .= "<br />$eBody\n"; $html .= "<br /><img src='$eImg' align='center' />\n"; } else { $html .= "<br />$eBody\n"; } $html .= "<br><br>$signature\n"; $html .= "</body></html>\n"; $eMsg->setTXTBody($emailTxt); $eMsg->setHTMLBody($html); $eMsg->addHTMLImage($logo, 'image/jpg', 'images/emailLogo.jpg', false); $eMsg->addHTMLImage($eImg, $imgTp, $eImg, true); $body = $eMsg->get(); $headers = array('To' => $eAdd, 'From' => 'me@you.com', 'Subject' => $eSubj, 'Reply-To' => 'me@you.com', 'Subject' => $eSubj); $hdrs = $eMsg->headers($headers, true); $addlParms = "-r me@you.com"; $mail =& Mail::factory('mail'); $retVal = $mail->send($to, $hdrs, $body, $addlParms); if (PEAR::isError($retVal)) { $myMsg = $tst_uname . "|$_SERVER[sCRIPT_NAME] sending email failed with error:|" . $retVal->getMessage() . "|" . $create_date . "\n"; logIt($myMsg); print "<script type='text/javascript'>alert('Failed to send the email! Email NOT sent!');window.location='tst.php';</script>\n"; exit; } print "<script type='text/javascript'>alert('email sent');window.location='tst.php';</script>\n"; exit; ?> Any help is greatly appreciated! David Quote Link to comment https://forums.phpfreaks.com/topic/86500-php-mailmime-attachment-and-embedded-images/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.