php - Why does my mail() class send twice? -


i got small problem mail class, reason mailing twice. , im not sure why, mail class:

<?php  class contact {  public $sendername; public $senderemail; public $recipient; public $copy; public $subject; public $message; public $bcc; public $errors;  public function __construct($sendername, $senderemail, $subject, $message){   $this->sendername = $sendername;   $this->senderemail = $senderemail;   $this->recipient = 'me@email.com'; //ofcourse not real email   $this->subject = $subject;   $this->message = $message;   $this->copy = '';   $this->bcc = '';   $this->errors = ''; }  public function sendmail() {         if ($this->sendername != "") {             $this->sendername = filter_var($this->sendername, filter_sanitize_string);             if ($this->sendername == "") {                 $this->errors .= '- please enter valid name!';             }         } else {             $this->errors .= '- forgot enter name!<br />';         }          if ($this->senderemail != "") {             $this->senderemail = filter_var($this->senderemail, filter_sanitize_string);             if ($this->senderemail == "") {                 $this->errors .= '- please enter valid email!';             }         } else {             $this->errors .= '- forgot enter email!<br />';         }          if ($this->subject != "") {             $this->subject = filter_var($this->subject, filter_sanitize_string);             if ($this->subject == "") {                 $this->errors .= '- please enter valid subject!';             }         } else {             $this->errors .= '- forgot enter subject!<br />';         }          if ($this->message != "") {             $this->message = filter_var($this->message, filter_sanitize_string);             if ($this->message == "") {                 $this->errors .= '- please enter valid message!';             }         } else {             $this->errors .= '- forgot enter message!<br />';         }          if (!$this->errors) {           $this->bcc="";            $headers = "from: $this->sendername <$this->senderemail>";           $headers .= "\r\ncc: $this->copy";           $headers .= "\r\nbcc: $this->bcc\r\n\r\n";            $send_contact = mail("$this->recipient","$this->subject","$this->message","$headers");           return true;           exit;          } else {           echo '<p class=\'message error\'>';           echo '<font color="#ffffff">' . $this->errors . '</font>';           echo '</p><br />';         } } } ?> 

i pretty sure shouldnt post twice, hope of guys can me out on one.

edit: added answer.

the 'return true' after mail() causing double send.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -