开发者

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.

I did a bit 开发者_如何学Goof 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? 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?


The following line get the contents of a HTML page.

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

Go here for full details: http://phpmailer.worxware.com/index.php?pg=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. Basically you can use fopen("Url", "r"), fsockopen("url", 80), or use a curl handler to submit the page request.

From here, depending on your method, you would read the response and generate an HTML or multi-part e-mail.

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 emails and Html pages are two totally different school.

Html emails take you back 10 years (hello tables!) in what you can do to support as many email clients as possible.

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜