PHPMailer - 无法加载 MsgHTML [英] PHPMailer - Unable to load MsgHTML

查看:38
本文介绍了PHPMailer - 无法加载 MsgHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHPmailer 向客户发送电子优惠券.我想将动态 html 文档作为正文文本发送给用户,但是当我引用此文件时,出现错误.

I am using PHPmailer in order to send an e-voucher to customers. I am wanting to send a dynamic html document to the user as the body text however when i refer to this file, i get an error.

我的代码如下:

$sessionid = '12345';
$cid = '98765';
require('class.phpmailer.php');
$bodytext1 = "Your Evoucher is attached for ".$row_checkout['name'];
$email = new PHPMailer();
$email->From      = 'noreply@xxx.com';
$email->FromName  = 'xxx.com';
$email->Subject   = 'Your e-voucher for '.$row_checkout['name'];
$email->AddAddress( $row_user['email'] );
$email->MsgHTML(file_get_contents('mail.php?sid='.$sessionid.'&cid='.$cartid));

$file_to_attach = $sessionid.'/'.$bookingid.'.pdf';

$email->AddAttachment( $file_to_attach , $bookingid.'.pdf' );
return $email->Send();

当我运行这个时,我收到以下错误:

When i run this, i get the following error:

Warning: file_get_contents(mail.php?sid=12345&cid=98765) [function.file-get-contents]: failed to open stream: No such file or directory in /home4/mission/public_html/xxx.com/evoucher/new/createandmail.php on line 93

但是,如果我不将变量放在 url 中,即

However, if I don't put the variables in the url, i.e.

$email->MsgHTML(file_get_contents('mail.php')

它发送得很好,但是一个没有正确字段的正文.

it sends fine but a with a body without the correct fields.

有什么建议吗?

推荐答案

您必须使用完整的 URL(包含协议:http://..)或使用文件名.mail.php?sid... 不是文件名 - 这是一个由 apache 处理的相对 uri.如果您使用 file_get_contents('mail.php'),则会发送原始 php 文件,这可能不是您想要的.

You have to use a full URL (containing the protocol: http://..) or use file names. mail.php?sid... isn't a filename - this is a relative uri which is handeld by apache. If you use file_get_contents('mail.php'), you send the raw php file, which might probably not what you want.

您也可以尝试使用 virtual 函数而不是使用 file_get_contents('http://server.com/mail.php?...'

You could also try the virtual function instead of using file_get_contents('http://server.com/mail.php?...'

这篇关于PHPMailer - 无法加载 MsgHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆