Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Ajax pattern to send email with a backend file to store an email address

Post

Ajax pattern to send email with a backend file to store an email address

+0
−4

I use the following backend (PHP) pattern to send email.

I consider to start sending email by Ajax but I would still need to store my email address in some backend file (say, a PHP file) so it won't be available to spambots via Developer tools → Sources.

What Ajax pattern will you use to do so?


behavior.php

<?php
	$name = $_POST['name']; # Required;
	$to = 'EMAIL_ADDRESS_NAME@DOMAIN';
	$subject = 'A new message from: ' . $name;
	$headers[] = 'MIME-Version: 1.0';
	$headers[] = 'Content-type: text/html; charset=utf-8';
	mail($to, $subject, $message, implode("\r\n", $headers));
?>

message.php

<?php
	$message = <<<LABEL
		<html>
			<body>
				<div><span class="form_output_col_1">Name: </span><span class="form_output_col_2">$name</span></div>
			</body>
		</html>
	LABEL;
?>
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

The answer to the Q "What Ajax pattern will you use to do so?" is: "None..." (2 comments)
The answer to the Q "What Ajax pattern will you use to do so?" is: "None..."
elgonzo‭ wrote almost 3 years ago · edited almost 3 years ago

Ajax is frontend-side (client-side). If you want to keep the email address in the backend (server-side), then it is a backend concern, not a frontend/Ajax concern. Therefore, the answer to your question "What Ajax pattern will you use to do so?" will be "None", because it is of no concern to the frontend of what the backend does internally "behind" its public API/endpoints...

r~~‭ wrote almost 3 years ago · edited almost 3 years ago

It's a badly worded question—the intent is clearly not ‘send an email with Ajax’; it's ‘use Ajax to submit data to the server’. Which is still confused, since ‘Ajax’ is nothing more than a somewhat obsolete name for a collection of web development patterns which includes techniques for submitting data to servers other than by navigating to a new page. The specific techniques have changed over time, so ‘use Ajax’ communicates nothing other than ‘I don't want to leave the page’.

This question should probably be, ‘What's the recommended way to send data to my PHP server without navigating to a new page?’ To which the answer is probably ‘use fetch’ and ‘you were on the right track with https://software.codidact.com/posts/285130; this question doesn't add any value on top of that one and should be closed’.