I’m creating a page with 4 buttons (the buttons will be 4 different images), so when you press any one of the buttons, an email is sent to the appropriate department.
For example, button 1 is for Math department, when you press button 1, an email is sent automatically to math@uni.com, press button 2, an email is automatically sent to music@uni.com and so on.
This project will be using a subdomain on my work’s website eg xxx.ourcompany.com How can I send an email automatically with a click of one of the four buttons using html, php or javascript if necessary?
(Ignore below if you have better ideas on how to do the task above, or it would be great if you could help me on the below issue) this is what I’ve found so far:
I saw a post that someone suggested the code below. I tried to duplicate the code for four buttons, but the email can’t be sent to every mail address from the subdomain (xxx.ourcompany.com).
Issue: The only email address is receiving the notification is an email address with our company’s name in it eg name@ourcompany.com but not yahoo or gmail account. I’m not sure what the reason is? Also what is a good way to stop spam as well? Your help is really appreciated.
<form action="" method="post">
<input type="submit" value="Send details to A" />
<input type="hidden" name="button_a" value="1" />
</form>
<?php
if(isset($_POST['button_a']))
{
$to = 'name@ourcompany.com'; //can receive notification
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@ourcompany.com' . "\r\n" .
'Reply-To: webmaster@ourcompany.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent.';
}
?>
I duplicate the code for the second button, but the yahoo or gmail email address can’t receive notification
<form action="" method="post">
<input type="submit" value="Send details to B" />
<input type="hidden" name="button_b" value="1" />
</form>
<?php
if(isset($_POST['button_b']))
{
$to = 'name@yahoo.com'; //can't receive notification!
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@ourcompany.com' . "\r\n" .
'Reply-To: webmaster@ourcompany.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent.';
}
?>
First of all, your emails are considered spam. Web mail providers like Gmail and Yahoo only receive email if they think the source is trustworthy. i get that a lot of times, when a co-worker emails me to my personal email using his company email. it always ends up in the spam.
and consider that your page is online, anyone can hack into it, and send spam all over your company using those one-click emailers you’re trying to create.
how about concentrating on building sort of inter-department messaging system. you’d have to enforce the departments to subscribe to this, maybe build a desktop app or web app for it so they see the messages easily. it’s better this way, sort of an “in-house twitter”.
or use twitter instead! 😀
or, i think this is possible, use an email client, and one company email. i think email clients today have “templates”.