Libcurl uses the following to define the email recipient:
#define RECIPIENT "<[email protected]>"
But what if I don't want to hard code the recipient? I want a user to be able to supply his/her own email address, so I need to find a way to do this:
std::string emailreceiver = "[email protected]";
#define RECIPIENT = emailreceiver
The recipient is used in this line:
rcpt_list = curl_slist_append(rcpt_list, RECIPIENT);
I'm assuming I can't simply change this to
std::string emailreceiver = "[email protected]";
rcpt_list = curl_slist_append(rcpt_list, emailreceiver);
Anyone have any suggestions?
Curl expects a C string (const char *
), not a C++ string (std::string
). So try:
std::string emailreceiver = "[email protected]";
rcpt_list = curl_slist_append(rcpt_list, emailreceiver.c_str());
There's no need to use a #define
at all, that was just an example.
Your last snippet is probably pretty close. From the looks of things, curl is expecting a C-style string though, so you may have to change it to:
std::string emailreceiver = "[email protected]";
rcpt_list = curl_slist_append(rcpt_list, emailreceiver.c_str());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With