title: How to send an automatic email at a click of a button?
body: <p>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. </p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p><strong>(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)</strong> this is what I've found so far: </p>
  
  <p>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). </p>
  
  <p>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.</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
  &lt;input type="submit" value="Send details to A" /&gt;
  &lt;input type="hidden" name="button_a" value="1" /&gt;
  &lt;/form&gt;
  
  &lt;?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.';
  }
  
  ?&gt;
  </code></pre>
  
  <p>I duplicate the code for the second button, but the yahoo or gmail email address can't receive notification </p>
  
  <pre><code>&lt;form action="" method="post"&gt;
  &lt;input type="submit" value="Send details to B" /&gt;
  &lt;input type="hidden" name="button_b" value="1" /&gt;
  &lt;/form&gt;
  
  &lt;?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.';
  }
  
  ?&gt;
  </code></pre>