Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用C+;轻松发送HTML格式电子邮件+;_C++_Html_Perl_Forms - Fatal编程技术网

C++ 用C+;轻松发送HTML格式电子邮件+;

C++ 用C+;轻松发送HTML格式电子邮件+;,c++,html,perl,forms,C++,Html,Perl,Forms,我有一个HTML表单,它当前接收输入并以HTML格式的电子邮件发送出去,因此电子邮件看起来基本上像表单网页,但所有字段都已填充 <form method="post" action="/cgi-bin/perlscript.pl" enctype="x-www-form-encoded" name="Form"> <input type="text" name="txtMyText" id="txtMyText" /> </form> < P>动作

我有一个HTML表单,它当前接收输入并以HTML格式的电子邮件发送出去,因此电子邮件看起来基本上像表单网页,但所有字段都已填充

<form method="post" action="/cgi-bin/perlscript.pl" enctype="x-www-form-encoded" name="Form">
   <input type="text" name="txtMyText" id="txtMyText" />
</form>

< P>动作脚本是用Perl编写的,我现在把它转换成C++只是因为我更容易阅读和维护。此外,我认为它对于将来的添加更加灵活

在Perl中,我可以使用“SendMail”发送电子邮件,我可以做如下操作:

sub PrintStyles
{
print MAIL <<ENDMAIL
<html>
    <head>
        <style>
        h1.title { color: Red; }
        h3.title { color : Black; background-color: yellow; }
        </style>

<!-- Put any valid HTML here that you want -->
<!-- You can even put variables ($xxxx) into the HTML as well, like this: -->
                <td>$myVariable</td>

ENDMAIL
}
cout << "<html>" << endl;
cout << "<head>" << endl;
cout << "......" << endl;
子打印样式
{
打印邮件

我所知道的最简单的方法是使用库中的类。
这里有一个。

我知道的最简单的方法是使用库中的类。
以下是一个。

您可以将文本定义为
常量字符*
,这将减轻通过
cout
输出每行的痛苦:

const char email_text[] =
"<html>\n"
"<head>\n"
"....";

cout.write(email_text, sizeof(email_text) - 1);
cout.flush();

std::string email_string(email_text);
cout << email_text;
cout.flush();
const char email_text[]=
“\n”
“\n”
"....";
书写能力(电子邮件文本,电子邮件文本大小)-1;
cout.flush();
std::string电子邮件字符串(电子邮件文本);

cout您可以将文本定义为
const char*
,这将减轻通过
cout
输出每行的痛苦:

const char email_text[] =
"<html>\n"
"<head>\n"
"....";

cout.write(email_text, sizeof(email_text) - 1);
cout.flush();

std::string email_string(email_text);
cout << email_text;
cout.flush();
const char email_text[]=
“\n”
“\n”
"....";
书写能力(电子邮件文本,电子邮件文本大小)-1;
cout.flush();
std::string电子邮件字符串(电子邮件文本);

CUT

你可以考虑

< P>你可以考虑

C++不支持这里的文档。 您需要使用字符串并将其发送到所需的流:

void PrintStyles(ostream& mailstream)
{

    mailstream <<  
    "<html>\n"
    "    <head>\n"
    "        <style>\n"
    "        h1.title { color: Red; }\n"
    "        h3.title { color : Black; background-color: yellow; }\n"
    "        </style>\n"
    "\n"
    "<!-- Put any valid HTML here that you want -->\n"
    "<!-- You can even put variables (" << xxxx << ") into the HTML as well, like this: -->\n"
    "                <td>" << myVariable << "</td>\n"
    "\n"
    "\n";
}
void打印样式(ostream和mailstream)
{

mailstreamC++不支持此处的文档。
您需要使用字符串并将其发送到所需的流:

void PrintStyles(ostream& mailstream)
{

    mailstream <<  
    "<html>\n"
    "    <head>\n"
    "        <style>\n"
    "        h1.title { color: Red; }\n"
    "        h3.title { color : Black; background-color: yellow; }\n"
    "        </style>\n"
    "\n"
    "<!-- Put any valid HTML here that you want -->\n"
    "<!-- You can even put variables (" << xxxx << ") into the HTML as well, like this: -->\n"
    "                <td>" << myVariable << "</td>\n"
    "\n"
    "\n";
}
void打印样式(ostream和mailstream)
{

邮件流

谢谢大家的回复。我决定简单地从我的代码中调用Perl脚本,并把响应数据作为参数发送。我知道这可能不是最好的解决方案,但我认为我的C++选项不值得。

// Retrieve the POST data    
char* contentLength = getenv{"CONTENT_LENGTH"};
int contentSize     = atoi(contentLength);
char* contentBuffer = (char*)malloc(contentSize);
fread(contentBuffer, 1, contentSize, stdin);
string data         = contentBuffer;

// Execute "sendmail.pl" script
string perlFile     = "sendmail.pl";
string command      = "perl " + perlFile + " \"" + data + "\"";
system(command.c_str());

谢谢大家的回复。我决定简单地从我的代码中调用Perl脚本,并把响应数据作为参数发送。我知道这可能不是最好的解决方案,但我认为我的C++选项不值得。

// Retrieve the POST data    
char* contentLength = getenv{"CONTENT_LENGTH"};
int contentSize     = atoi(contentLength);
char* contentBuffer = (char*)malloc(contentSize);
fread(contentBuffer, 1, contentSize, stdin);
string data         = contentBuffer;

// Execute "sendmail.pl" script
string perlFile     = "sendmail.pl";
string command      = "perl " + perlFile + " \"" + data + "\"";
system(command.c_str());

C/C++不支持文档,它需要引用字符串,但是编译器会自动将源文件中的多个字符串串联起来。不要使用<代码> EntL\/Calp>。只使用<代码> > n '/COD>。它更快,也很方便。C++中必须有一个好的模板库来生成电子邮件体。生成电子邮件本身,但HTML消息的正文应该由模板引擎完成。@Omnifarious:你是说性能更快吗?我更喜欢保留“endl”因为视觉上的原因而分开,我可以比\n更快地键入它。是的,性能更好。它一直在刷新,并且输出大量完全不必要的HTML。应该有人想出一个名称很好的字符常量,供所有人使用,它不会一直刷新。C/C++不支持文档。它需要一个引号ED String。但是编译器会自动将源代码文件中的多个字符串串联起来。不要使用<代码> EntL\/Calp>。只使用<代码> > \n′/COD>。它更快,也很方便。C++中必须有一个好的模板库来生成电子邮件体。你需要一个漂亮的MIME库来生成电子邮件本身,但是HTML的混乱体。年龄应该由模板引擎完成。@Omnifarious:你是说在性能上更快吗?我更喜欢保留“endl”由于视觉原因而分开,我可以比\n更快地键入它。是的,性能更好。它一直在刷新,并且输出大量完全不必要的HTML。应该有人想出一个名称很好的字符常量,供所有人使用,它不会一直刷新。谢谢你的链接。我不熟悉这个术语“这里的文件。”谢谢你的链接。我不熟悉“这里的文件”这个词