使用 mailgun 发送动态 php 页面

Sending dynamic php page with mailgun

我正在尝试通过 PHP 中的 mailgun API 发送动态电子邮件,但我没有任何运气。

如果我只发送简单的动态内容,我可以成功发送电子邮件。例如。

$email = test@test.com;
$firstname = Tester;
$result = $mgClient->sendMessage($domain, array(
'from'    => 'Support Team <hello@xyz.com>',
'to'      => $email,
'subject' => 'Welcome to XYZ.com',
'html'    => "<html>Dear $firstname, this is a test.</html>"
), array(

));

但是我希望能够从动态页面中提取内容,例如 welcomeemail.php?userid=1。所以我尝试使用:

$html = file_get_contents(welcomeemail.php?userid=1
'html'   => $html

但是我收到以下错误 "警告:file_get_contents(welcomeemail.php?userid=1): 无法打开流:没有这样的文件或目录。

当我删除 ?userid=1 时,它工作正常但显然没有动态内容。

您能否就如何将动态内容合并到我的电子邮件中提供任何建议?

您应该将完整的 http 路径放入 welcomeemail.php。例如 file_get_contents('http://localhost/welcomeemail.php?userid=1')。如果您不这样写,file_get_contents() 会在文件系统中查找显然不存在的文件 'welcomeemail.php?userid=1'。