简体   繁体   English

PHP从网站发送HTML EMAIL页面

[英]PHP sending an HTML EMAIL Page from a website

I've used PHP to send emails before but never to send a full HTML page from another source and so I'm wondering where to start and a few other things. 我之前使用PHP发送电子邮件,但从未从其他来源发送完整的HTML页面,所以我想知道从哪里开始和其他一些事情。

I did a bit of research but my confusion isn't clearing up any. 我做了一些研究,但我的困惑并没有消除任何问题。

Do I directly get the web-page contents and send that or can I use a setting to just use a URL? 我是直接获取网页内容并发送,还是可以使用设置来使用URL? What is the simplest method I could use and could someone show me an example? 我可以使用的最简单的方法是什么,有人可以给我一个例子吗? Are there risks with sending an email like this to say... 5000 people and how do I change the header data with a return link to URL source? 发送这样的电子邮件是否存在风险... 5000人以及如何使用URL源的返回链接更改标题数据?

The following line get the contents of a HTML page. 以下行获取HTML页面的内容。

 $mail->MsgHTML(file_get_contents('contents.html'));

Go here for full details: http://phpmailer.worxware.com/index.php?pg=exampleagmail 请访问此处获取完整详细信息: http//phpmailer.worxware.com/index.php?ppg = exampleagmail

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$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->Host       = "mail.yourdomain.com"; // SMTP server
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = 587;                   // set the SMTP port for the GMAIL server
  $mail->Username   = "yourusername@gmail.com";  // GMAIL username
  $mail->Password   = "yourpassword";            // GMAIL password
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  $mail->SetFrom('name@yourdomain.com', 'First Last');
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML(file_get_contents('contents.html'));
  $mail->AddAttachment('images/phpmailer.gif');      // attachment
  $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  $mail->Send();
  echo "Message Sent OK\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}

Disclaimer: I can't yet comment, so please forgive this being an "answer". 免责声明:我还不能评论,所以请原谅这是一个“答案”。

I think you're probably going to have to clarify your objectives a little bit here. 我想你可能不得不在这里澄清一下你的目标。

It sounds like what you want to do is first build a basic scraper unless you have access to the raw html file. 听起来你想要做的就是首先构建一个基本的刮刀,除非你有权访问原始的html文件。 Basically you can use fopen("Url", "r"), fsockopen("url", 80), or use a curl handler to submit the page request. 基本上你可以使用fopen(“url”,“r”),fsockopen(“url”,80),或者使用curl处理程序来提交页面请求。

From here, depending on your method, you would read the response and generate an HTML or multi-part e-mail. 从这里开始,根据您的方法,您将阅读响应并生成HTML或多部分电子邮件。

As far as adding a link to the e-mail header, you can do that, but I have a feeling it's not going to do what you want it to. 至于添加电子邮件标题的链接,你可以这样做,但我觉得它不会做你想要的。 The way to do it will depend on how you decide to send the e-mail. 这样做的方式取决于您决定发送电子邮件的方式。

Ives' answer is nice. 艾夫斯的回答很好。

There is one gotcha you really want to consider with emailing an html page. 通过电子邮件发送html页面,你真的想要考虑一个问题。

Html emails and Html pages are two totally different school. Html电子邮件和Html页面是两个完全不同的学校。

Html emails take you back 10 years (hello tables!) in what you can do to support as many email clients as possible. Html电子邮件将带您回到10年(问候表!),您可以采取哪些措施来支持尽可能多的电子邮件客户端。

It's very likely a straight email-a-webpage thing will look total crap on the recipient email.. 这很可能是一个直接的电子邮件 - 网页的东西看起来总收看邮件的垃圾邮件..

and then you've got to consider embedding stylesheets, etc.. 然后你必须考虑嵌入样式表等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM