【问题标题】:Sending contents of a php file (dynamically loaded using Jquery load method) using PHPMailer使用 PHPMailer 发送 php 文件的内容(使用 Jquery 加载方法动态加载)
【发布时间】:2013-04-28 08:38:20
【问题描述】:

这是我对这个社区的第一个问题。但是,我长期以来一直在使用它来解决任何技术难题,这对我很有帮助。

无论如何我的问题是:

我正在从另一个 PHP 文件 shopping_cart.php 加载 mail_contents.php 的 div 中的内容:

$("#mail_contents").load('shopping_cart.php #cart_contents');

当我在浏览器中直接打开 mail_contents.php 时,我也可以看到内容。

但问题是当我尝试使用以下代码在电子邮件中发送此 php 文件的内容时:

.....
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
$mailer->IsHTML(true); 

$mailer->AddAddress($this->UserEmail());

$mailer->Subject = "You have placed an order with ".$this->sitename;

$mailer->From = $this->GetFromAddress();

$mailer->FromName = "POR";   

ob_start();
include 'mail_contents.php';

$content = ob_get_clean();

$mailer->Body = $content;

if(!$mailer->Send()){
$this->HandleError("Failed sending user welcome email.");
return false;
}
return true;
....

我看不到动态加载的内容。我使用 echo 语句在我的 mail_contents.php 文件中添加了一些静态代码,我发现它成功地出现在我的电子邮件中。如果我做错了什么,请指导我。

谢谢提前!!

【问题讨论】:

  • 我还需要提供一些其他信息吗?

标签: php jquery phpmailer


【解决方案1】:

试试这个:

ob_start();
   include 'mail_contents.php';
$content = ob_get_clean();

$mail->MsgHTML($content, dirname(__FILE__));

告诉我,这是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2011-06-14
    • 2017-05-05
    • 1970-01-01
    相关资源
    最近更新 更多