我一直在尝试使用 PHP Mail 函数发送带有 HTML 正文和附件的电子邮件。没有附加文件,我可以毫无问题地收到我的 HTML 电子邮件,但是当我尝试附加文件时,我在正文中得到了所有 MIME 信息——还有附件,已编码。
这是没有附件的电子邮件功能的代码 - 工作正常:
$this->to = $to;
$this->subject = $subject;
$this->message = $message;
$this->headers = "From: " . Mailer::FROM_EMAIL . "\r\n";
$this->headers .= "MIME-Version: 1.0\r\n";
$this->headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
这是带有附件的电子邮件版本的代码:
$this->to = $to;
$this->subject = $subject;
$this->attachment =
chunk_split(base64_encode(file_get_contents($attachment)));
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$boundary = md5(date('r', time()));
$this->headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com\r\n";
$this->headers .= "MIME-Version: 1.0\r\n ";
$this->headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$boundary\"\r\n";
$this->message =
"--PHP-mixed-$boundary
Content-Type: text/html; charset=\"ISO-8859-1\"
" . $message . "
--PHP-mixed-$boundary
Content-Type: application/pdf; name=\"test.pdf\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
".$this->attachment ."
--PHP-mixed-$boundary--";
我正在使用此功能发送电子邮件:
public function send(){
if (preg_match(Mailer::PATTERN, trim(strip_tags($this->to)))) {
$cleanedTo = trim(strip_tags($this->to));
} else {
return FALSE;
}
return mail ($cleanedTo, $this->subject, $this->message, $this->headers);
}
然后我按如下方式创建 Mailer 对象:
$mailer = new Mailer("youremail@gmail.com", "test mail", "Some <b>old good</b> HTML email", 'pdf/test.pdf');
//$mailer = new Mailer("youremail@gmail.com", "test mail", "Some <b>old good</b> HTML email");
$mailer->send();
我收到的邮件是:
--PHP-mixed-e37929b72bbc6f8e3b37cf802619aac1
Content-Type: text/html; charset="ISO-8859-1"
Some <b>old good</b> HTML email
--PHP-mixed-e37929b72bbc6f8e3b37cf802619aac1
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
JVBERi0xLjMKMSAwIG9iago8 ... FT0YK
--PHP-mixed-e37929b72bbc6f8e3b37cf802619aac1--
我想我真的很接近答案,但是......我需要你的帮助才能找到它。
最佳答案
$this->headers .= "MIME-Version: 1.0\r\n "; $this->headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$boundary\"\r\n";
删除 MIME-Version 行中换行符后的空格。 Content-Type 前面的这个尾随空格将使它成为前一行的延续。
顺便说一句:如果您的代码在 Linux/Unix 上运行,请仅在每行末尾使用“\n”。
关于php - 邮件正文中的 MIME 信息与 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14022271/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
如果我有以下一段Ruby代码:classBlahdefself.bleh@blih="Hello"@@bloh="World"endend@blih和@@bloh到底是什么?@blih是Blah类中的一个实例变量,@@bloh是Blah类中的一个类变量,对吗?这是否意味着@@bloh是Blah的类Class中的一个变量? 最佳答案 人们似乎忽略了该方法是类方法。@blih将是常量Bleh的类Class实例的实例变量。因此:irb(main):001:0>classBlehirb(main):002:1>defself.blehirb
我遇到了这个奇怪的错误.../Users/gideon/Documents/ca_ruby/rubytactoe/lib/player.rb:13:in`gets':Isadirectory-spec(Errno::EISDIR)player_spec.rb:require_relative'../spec_helper'#theuniverseisvastandinfinite...itcontainsagame....butnoplayersdescribe"tictactoegame"docontext"theplayerclass"doit"musthaveahumanplay
我想验证一个电子邮件地址是否是PayPal用户。是否有API调用来执行此操作?是否有执行此操作的ruby库?谢谢 最佳答案 GetVerifiedStatus来自PayPal'sAdaptiveAccounts平台会为您做这件事。PayPal没有任何codesamples或SDKs用于Ruby中的自适应帐户,但我确实找到了编写codeforGetVerifiedStatusinRuby的人.您需要更改该代码以检查他们拥有的帐户类型的唯一更改是更改if@xml['accountStatus']!=nilaccount_status
我在Ruby程序中有两个URI。一个肯定是绝对URI,另一个可能是绝对URI或相对URI。我想在第一个的上下文中将第二个转换为绝对URI,所以如果第一个是http://pupeno.com/blog第二个是/about,结果应该是http://pupeno.com/about.有什么想法吗? 最佳答案 Ruby的内置URI和Addressablegem,做这个简短的工作。我更喜欢Addressable,因为它功能更全面,但URI是内置的。require'uri'URI.join('http://pupeno.com/blog','/
我想知道我应该如何着手这个项目。我需要每周向人们发送一次电子邮件。但是,这必须在每周的特定时间自动生成并发送。编码有多难?我需要知道是否有任何书籍可以提供帮助,或者你们中的任何人是否可以指导我。它必须使用rubyonrails进行编程。因此有一个网络服务和数据库集成。干杯 最佳答案 为什么这么复杂?您只需安排工作。您可以使用Delayed::Job例如。Delayed::Job让您可以使用run_at符号在特定时间安排作业,如下所示:Delayed::Job.enqueue(SendEmailJob.new(...),:run_
我有两个文本文件,master.txt和926.txt。如果926.txt中有一行不在master.txt中,我想写入一个新文件notinbook.txt。我写了我能想到的最好的东西,但考虑到我是一个糟糕的/新手程序员,它失败了。这是我的东西g=File.new("notinbook.txt","w")File.open("926.txt","r")do|f|while(line=f.gets)x=line.chompifFile.open("master.txt","w")do|h|endwhile(line=h.gets)ifline.chomp!=xputslineendende