我正在创建一个电子邮件服务,使用phpmail将不同的图像发送给不同的人。我可以根据需要发送邮件和附件,但是当涉及到动态添加邮件正文中的嵌入图像时。 我无法取得成功。
<?php require_once('class.phpmailer.php'); // multiple recipients $to = $arr['Contact.Email']; // note the comma $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->IsSMTP(); // telling the class to use SMTP try{ $mail->SetFrom($arr['Contact.Email'], 'First Last'); $mail->AddAddress($arr['Contact.Email'], 'John Doe'); $mail->Subject = 'PHPMailer Test'; $mail->AddEmbeddedImage($arr['ContactId'].'.png', 'my-attach'); $mail->Body = 'Your <b>HTML</b> with an embedded Image: <img src=cid:my-attach\'> Here is an image!'; $mail->AddAttachment($arr['ContactId'].".png"); // this is a regular attachment (Not inline) $mail->Send(); echo "Message Sent OK<p></p>\n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); } ?>我可以嵌入一个图像,但当我尝试为不同的用户发送不同的图像我得到一个错误。我搜索到处,但我没有得到任何令人满意的答案。 任何帮助将不胜感激。
I am creating a email service which send different image to different person using phpmail.I can send mail and attachment as i require but when it comes to dynamically adding embedded image in body of mail. I wont be able to achieve success.
<?php require_once('class.phpmailer.php'); // multiple recipients $to = $arr['Contact.Email']; // note the comma $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->IsSMTP(); // telling the class to use SMTP try{ $mail->SetFrom($arr['Contact.Email'], 'First Last'); $mail->AddAddress($arr['Contact.Email'], 'John Doe'); $mail->Subject = 'PHPMailer Test'; $mail->AddEmbeddedImage($arr['ContactId'].'.png', 'my-attach'); $mail->Body = 'Your <b>HTML</b> with an embedded Image: <img src=cid:my-attach\'> Here is an image!'; $mail->AddAttachment($arr['ContactId'].".png"); // this is a regular attachment (Not inline) $mail->Send(); echo "Message Sent OK<p></p>\n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); } ?>I can embed one image but when i try to send different image for different user i get an error.I searched everywhere but i did not get any satisfactorily answer. any help will be appreciated.
最满意答案
你有一个错误:
$mail->Body = 'Your <b>HTML</b> with an embedded Image: <img src=cid:my-attach\'> Here is an image!';您需要在附加后跳过\' 。
您还需要通过添加以下内容将消息设置为html格式:
$mail->IsHTML(true);在此处阅读有关在文档中嵌入图像的更多信息: http : //phpmailer.worxware.com/?pg = tutorial
You have an error at:
$mail->Body = 'Your <b>HTML</b> with an embedded Image: <img src=cid:my-attach\'> Here is an image!';You need to skip the \' after attach.
You also need to set the message to html format by adding:
$mail->IsHTML(true);Read more about embedding images in the docs here: http://phpmailer.worxware.com/?pg=tutorial
更多推荐
发布评论