Hello,
I’m probably making a stupid mistake, but I’m having issues sending an email from Lua with PHP. I poromised this to someone who wanted PHP tutorials earlier, but I ran into issues. I needed it for my own app, so I tried to fix the issue, but I can’t. Can someone help please?
function setup()
sendEmail("<deleted>","<deleted>","Subject","Line 1\
Line2\
Line 3")
end
function draw()
background(40, 40, 50)
end
function sendEmail(to,from,subject,message)
-- Functino for encoding string as URL (from lua-users.org/wiki/StringRecipes)
local function urlEncode(str)
if (str) then
str = string.gsub (str, "\
", "\\r\
")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
-- Set up initial URL
local url = "<deleted>"
-- Set up headers (to spoof the email coming from an email and setting up the reply-to feild
local headers = "From: "..from.."\
Reply-To: "..from
-- Tell PHP what to send in the email
urlVars = "?to="..to.."&subject="..subject.."&message="..message.."&headers="..headers
-- Encode URL variables and join with main URL
url = url..urlEncode(urlVars)
print(url)
-- Sends request
http.request(url,
function(data)
-- Success
print("Success\
Data received: "..data)
end,
function(error)
-- Fail
print("Fail with error: "..error)
end)
print("Request sent")
end
and the PHP:
<?php
$to = $_GET["to"];
$subject = $_GET["subject"];
$message = $_GET["message"];
$headers = $_GET["headers"];
//$headers = "From: - \\r\
Reply-To: -";
//$message = str_replace("/r/n", "\\r\
", $message);
//$headers = str_replace("/r/n", "\\r\
", $headers);
if(mail($to, $subject,$message,$headers)){
echo 'Email sent';
}
else{
echo 'Error in sending email';
}
?>
My issue is that I’m getting only the first line of the email.
I can do this perfectly in JavaScript with RegEx.
Thanks!
( @Briarfox - I know you know stuff about PHP )
Also, please do not spam my email or servers. Thank you. I will be moving this file soon, so don’t plan on being able to use it.