Highlighted

Spam, or not received at all, from mail form (new title: Please, check out my mail form)

New Here ,
Jan 11, 2020

Copy link to clipboard

Copied

Best Adobe Support Community,

 

Messages sent from my mail form either ended up in spam or was not received at all.  It turned out that "$headers = "From: $name <$email>" was the problem, because a message through a mail form is not necessarily sent from the users email provider (obviously). Hence the domain address entered is different from which it is sent. No wonder...

 

Before you check out my code observe that x's represent secret information and that "domain.com" is nonspecific.

 

So I changed to the following (I also included $email in the $message):

 

$to = "xxx@domain.com";
$subject = "Message from visit at xxx@domain.com";
$message = "From:"."\r\n".$email."\r\n"."Message:"."\r\n".$message;
$headers = "reply-to: $email";

 

Edit: A new problem is the message field... I tried writing a longer message that was not received at all... I also tried adding multiple periods and apostrophes, which also turned out blank. So, please, explain what has to be changed regarding the result of the function "test_input" concerning the message field.

 

I really call for for a careful examination of the whole PHP down below. Thank you so much on beforehand:

 

<?php


/* variable definition */
$name = $email = $message = $submit = $recaptcha = "";
$errors = $success = array();
/* end of "variable definition" */


if (isset($_POST["submit"])) {
/* when submit is pressed */


/* test_input function definition */
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
/* end of "test_input function definition" */


/* process the name field */
if (empty($_POST["name"])) {
$errors['name'] = "A name must be entered";
}
else {
$name = test_input($_POST["name"]);
if (preg_match("/^[a-zA-Z ]*$/", $name) == FALSE) {
$errors['name'] = "Only letters, except &aring;&auml;&ouml;&Aring;&Auml;&Ouml;, and blank space are allowed.";
}
}
/* end of "process the name field" */


/* process the email field */
if (empty($_POST["email"])) {
$errors['email'] = "An email address must be entered.";
}
else {
$email = test_input($_POST["email"]);
if (filter_var($email, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE) == FALSE) {
$errors['email'] = "Wrong email format.";
}
}
/* end of "process the email field" */


/* process the message field */
if (empty($_POST["message"])) {
$errors['message'] = "A message must be entered.";
}
else {
$message = test_input($_POST["message"]);
}
/* end of "process the message field" */


/* check google recaptcha box */
if (empty($_POST["g-recaptcha-response"])) {
$errors['recaptcha'] = "Confirm that you are not a robot!";
}
else {
$recaptcha = $_POST["g-recaptcha-response"];
$secret = "xxx";
$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$recaptcha));
if ($response->success) {
}
else {
$errors['recaptcha'] = "Robot verification failed!\r\nPlease try again!";
}
}
/* end of "check google recaptcha box" */


/* if no errors */
if (count($errors) == 0) {
$to = "xxx@domain.com";
$subject = "Message from visit at xxx@domain.com";
$message = "From:"."\r\n".$email."\r\n"."Message:"."\r\n".$message;
$headers = "reply-to: $email";
if (mail($to, $subject, $message, $headers) == TRUE) {
$success['success'] = "Message was sent successfully!";
/* field input is removed when successful */
$name = $email = $message = "";
/* end of "field input is removed when succesful" */
}
else {
$errors['mail'] = "Something went wrong!\r\nPlease try again!";
}
}
/* end of "if no errors" */


/* end of "when submit is pressed" */
}


?>

 

[Edited by moderator to restore default text and code styles.]

Adobe Community Professional
Correct answer by Nancy_OShea | Adobe Community Professional

When form data goes to your spam folder, it's usually because YOUR server's spam filter settings are too strict.  Or perhaps your hosting company wants you to use SMTP Authentication to send mail.  For that you need an entriely different PHP script or library.

 

PHP Mailer on GitHub is a popular option recommended by many hosting companies.

https://github.com/PHPMailer/PHPMailer

 

 

Topics

Code, How to, Other

Views

367

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Spam, or not received at all, from mail form (new title: Please, check out my mail form)

New Here ,
Jan 11, 2020

Copy link to clipboard

Copied

Best Adobe Support Community,

 

Messages sent from my mail form either ended up in spam or was not received at all.  It turned out that "$headers = "From: $name <$email>" was the problem, because a message through a mail form is not necessarily sent from the users email provider (obviously). Hence the domain address entered is different from which it is sent. No wonder...

 

Before you check out my code observe that x's represent secret information and that "domain.com" is nonspecific.

 

So I changed to the following (I also included $email in the $message):

 

$to = "xxx@domain.com";
$subject = "Message from visit at xxx@domain.com";
$message = "From:"."\r\n".$email."\r\n"."Message:"."\r\n".$message;
$headers = "reply-to: $email";

 

Edit: A new problem is the message field... I tried writing a longer message that was not received at all... I also tried adding multiple periods and apostrophes, which also turned out blank. So, please, explain what has to be changed regarding the result of the function "test_input" concerning the message field.

 

I really call for for a careful examination of the whole PHP down below. Thank you so much on beforehand:

 

<?php


/* variable definition */
$name = $email = $message = $submit = $recaptcha = "";
$errors = $success = array();
/* end of "variable definition" */


if (isset($_POST["submit"])) {
/* when submit is pressed */


/* test_input function definition */
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
/* end of "test_input function definition" */


/* process the name field */
if (empty($_POST["name"])) {
$errors['name'] = "A name must be entered";
}
else {
$name = test_input($_POST["name"]);
if (preg_match("/^[a-zA-Z ]*$/", $name) == FALSE) {
$errors['name'] = "Only letters, except &aring;&auml;&ouml;&Aring;&Auml;&Ouml;, and blank space are allowed.";
}
}
/* end of "process the name field" */


/* process the email field */
if (empty($_POST["email"])) {
$errors['email'] = "An email address must be entered.";
}
else {
$email = test_input($_POST["email"]);
if (filter_var($email, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE) == FALSE) {
$errors['email'] = "Wrong email format.";
}
}
/* end of "process the email field" */


/* process the message field */
if (empty($_POST["message"])) {
$errors['message'] = "A message must be entered.";
}
else {
$message = test_input($_POST["message"]);
}
/* end of "process the message field" */


/* check google recaptcha box */
if (empty($_POST["g-recaptcha-response"])) {
$errors['recaptcha'] = "Confirm that you are not a robot!";
}
else {
$recaptcha = $_POST["g-recaptcha-response"];
$secret = "xxx";
$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$recaptcha));
if ($response->success) {
}
else {
$errors['recaptcha'] = "Robot verification failed!\r\nPlease try again!";
}
}
/* end of "check google recaptcha box" */


/* if no errors */
if (count($errors) == 0) {
$to = "xxx@domain.com";
$subject = "Message from visit at xxx@domain.com";
$message = "From:"."\r\n".$email."\r\n"."Message:"."\r\n".$message;
$headers = "reply-to: $email";
if (mail($to, $subject, $message, $headers) == TRUE) {
$success['success'] = "Message was sent successfully!";
/* field input is removed when successful */
$name = $email = $message = "";
/* end of "field input is removed when succesful" */
}
else {
$errors['mail'] = "Something went wrong!\r\nPlease try again!";
}
}
/* end of "if no errors" */


/* end of "when submit is pressed" */
}


?>

 

[Edited by moderator to restore default text and code styles.]

Adobe Community Professional
Correct answer by Nancy_OShea | Adobe Community Professional

When form data goes to your spam folder, it's usually because YOUR server's spam filter settings are too strict.  Or perhaps your hosting company wants you to use SMTP Authentication to send mail.  For that you need an entriely different PHP script or library.

 

PHP Mailer on GitHub is a popular option recommended by many hosting companies.

https://github.com/PHPMailer/PHPMailer

 

 

Topics

Code, How to, Other

Views

368

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jan 13, 2020

Copy link to clipboard

Copied

When form data goes to your spam folder, it's usually because YOUR server's spam filter settings are too strict.  Or perhaps your hosting company wants you to use SMTP Authentication to send mail.  For that you need an entriely different PHP script or library.

 

PHP Mailer on GitHub is a popular option recommended by many hosting companies.

https://github.com/PHPMailer/PHPMailer

 

 

Nancy O'Shea, ACP
Alt-Web.com

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jan 14, 2020

Copy link to clipboard

Copied

Thank you so much as always, Nancy! 🙂

 

Since this was the issue I set out to solve I will award you with the correct answer. I will use SMTP Authentication for my new website. Also, I am implementing client-side validation as was recommended by you guys before!

 

But before then, how do you explain a mail being received to the inbox but with the message being removed...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jan 14, 2020

Copy link to clipboard

Copied

If the message didn't come through, that's almost always a scripting error.  Check that all variables are defined and named properly in the PHP script as well as the HTML form.  

 

Nancy O'Shea, ACP
Alt-Web.com

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jan 15, 2020

Copy link to clipboard

Copied

Nancy, I ask for patience so don't get irritated with me, he, he...

However, the message comes through when I, for instance, just type in a string of letters without spaces or any other symbol... I tried sending a message with only periods and apostrophes and it didn't go through. Worst of all is that it didn't go through when just typing a longer message and not omitting spaces and periods...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...