I have a coupon page where the user enters their email address and gets a random string to their email.
I want to check first if the user has already signed up for a coupon code by searching in coupon.txt
; if one is already present an error is output, otherwise a coupon is sent.
This is my code for sending the email:
$mailed = false;
if (!empty($name) && !empty($email) )
$mailed = mail($emailTo, $subject, $body, $headers, $randomString);
if($mailed == true) {
echo json_encode(array('status' => 'ok'));
file_put_contents("coupon.txt", $email. . $RandomString . PHP_EOL, FILE_APPEND);
mail($email, "praia", $message , $headers2);
} else {
echo json_encode(array('status' => 'error'));
}