/    Sign up×
Community /Pin to ProfileBookmark

I’m sure this is easy for you (php mail)

Most web forms check for empty fields and then require an input before you send anything. In my form, I want to do the opposite. If the form contains no data, I’d like to trash the message and still put up a ‘thank you page’.

What do I need to do to disallow the form to mail its empty message to me?

Thanks,
Stefan

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulMar 15.2015 — Instead of two results of validation:

- fail - loop back with error message.

-pass - continue and send email.

You may just need two results:

- fail - continue but do not send email.

-pass - continue and send email.

Or you may need three results:

- fail - other - loop back with error message.

- fail - blank - continue but do not send email.

-pass - continue and send email.

That depends on whether all failures are treated the same.
Copy linkTweet thisAlerts:
@stefangsauthorMar 16.2015 — That depends on whether all failures are treated the same.[/QUOTE]

Yes, all fails are treated equally. I do not actually want to check on the validity of input, just for useless links (spam in messages) and blank messages which are probably posted by mistake or by bots.

So, to check for blank messages, would I create a variable and add all strings in the form (3 fields) together? Sorry, I'm quite ignorant in php.

Nice avatar, btw ?

Thanks,

Stefan
Copy linkTweet thisAlerts:
@rootMar 16.2015 — What have your done so far with scripting?

testing a field if it is empty is as easy as using the empty() function of PHP

You will however, need to address the issue of sanitizing inputs in to our script via $_POST and $_GET methods of passing form data.

It is in this part of the process that you can find if any fields are empty.
Copy linkTweet thisAlerts:
@stefangsauthorMar 17.2015 — What have your done so far with scripting?[/QUOTE]

You can see a live demo of my script here:

http://www.root-sounds.com/spamtest_webdev.shtml

All the other lines are working just fine now. I'm actually quite happy with it, but it seems like everything is always a work in progress ?

I now tried this (for testing):

if (!empty($comments));

echo "No message!";

exit;

Seems to work ok. Probably not very elegant, but whatever works. Now I only need to take out the echo and I'm all set, right?

Thanks,

Stefan
Copy linkTweet thisAlerts:
@Strider64Mar 18.2015 — I like the hidden Captcha ?
Copy linkTweet thisAlerts:
@rootMar 18.2015 — Sorry, you seem to misunderstand my question, what I was asking you was for you to post the PHP code you are having a problem with and no links to external sites, post here and use form tags (see my signature) and indicate the point where the error is or part you are having an issue with.
Copy linkTweet thisAlerts:
@stefangsauthorMar 18.2015 — Sorry, you seem to misunderstand my question, what I was asking you was for you to post the PHP code you are having a problem with and no links to external sites, post here and use form tags (see my signature) and indicate the point where the error is or part you are having an issue with.[/QUOTE]

Part of my problem was the fact that I didn't have any code to begin with. But as it is, thanks to your post above I found a workable solution (see my post above) so I'm all set.

Thanks,

Stefan
Copy linkTweet thisAlerts:
@Vikas_PatelMar 20.2015 — For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file.
Copy linkTweet thisAlerts:
@rootMar 20.2015 — Still no code post...

If you are having email issues, you need to as suggested have access to an email account on the domain sending emails, some hosting companies use an object to capture and direct the send mail from the form to the email server to send via the specified email account.

Best thing for you to do is read up about sending PHP emails in your web hosts wiki / info page.
Copy linkTweet thisAlerts:
@stefangsauthorMar 21.2015 — Hmm.. seems to be a misunderstanding here. There's no problem sending emails. This contact web page and its associated php script are alive and well on my web space. I now included the lines

if (!empty($comments));

echo "Thank you for your message!";

exit;

to the php file. This makes the poster (presumably an erroneous post or a bot) think that the message was delivered when in fact, it wasn't. That's exactly what I wanted ?

Thanks,

Stefan
Copy linkTweet thisAlerts:
@rootMar 22.2015 — You're asking for help with your web code but not posting any of it, were not miracle workers you know...

To get help you need to post the code your using, posting snipits without wrapping the code doesn't help either... Use forum tags please. [code=php]
if (!empty($comments));
echo "Thank you for your message!";
exit;
[/code]


The snippit of code does not tell us much about what problems you are trying to solve.
Copy linkTweet thisAlerts:
@stefangsauthorMar 23.2015 — 
[code=php]
if (!empty($comments));
echo "Thank you for your message!";
exit;
[/code]


The snippit of code does not tell us much about what problems you are trying to solve.[/QUOTE]


No, the snippet of code shows that the problem is already solved, because I needed the (!empty) function.

Sorry I didn't know about how to wrap the code.

Thanks,

Stefan
×

Success!

Help @stefangs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...