我将尝试用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;
I call the function like this:
sendMail("template", "Account Activation", $USR_Id, $USR_Email);
奇怪的是,当我回显 $message
时,它没有回显 Subject is : ...
。它回显了 Subject is : '.$_POST['subject'].'
。就像 PHP 不起作用一样...
请问有人可以帮助我吗?
谢谢。
$message
吗?它似乎只是一个变量! - Kiyarashecho
... 对于这种情况,返回不合适... - Kiyarash../../
你能提供你的文件结构吗?尝试使用这个工具来帮助你在文本中创建它:http://filestructuregenerator.com - CodeGodie$context
。PHP也无法运行。 - mario