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;
?>
1 comment thread