【发布时间】:2015-06-28 02:02:08
【问题描述】:
我正在尝试使用 PHP 发送电子邮件。
我的问题其实是,发送的邮件是空白的……
我的 PHP 函数:
function sendMail($template, $Email_Subject, $USR_Id, $USR_Email) {
$postdata = http_build_query(
array(
'subject' => $Email_Subject
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$message = file_get_contents('../../mail/'.$template.'.php', false, $context);
// Start configuring the email
$headers .= 'From: Company <noreply@company.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($USR_Email, $Email_Subject, $message, $headers);
}
我的 template.php 页面:
$message =
'<html>
...
<h1>Subject is : '.$_POST['subject'].'</h1>
...
<\html>';
echo $message;
我这样调用函数:
sendMail("template", "Account Activation", $USR_Id, $USR_Email);
奇怪的是,当我回显$message 时,它没有回显我Subject is : ...。它呼应了我Subject is : '.$_POST['subject'].'。就像如果 PHP 不工作...
有人帮帮我吗?
谢谢。
【问题讨论】:
-
你在 template.php 中回显
$message吗?好像只有一个变量!!! -
是的。我也尝试过返回。
-
用
echo试试吧...返回不适合这种情况... -
我尝试了 echo $message。同样... :(
-
可能您的文件路径不正确。
../../你能提供你的文件结构吗?尝试使用此工具帮助您在文本上创建它:filestructuregenerator.com