YaWK  24.1
Yet another WebKit
email.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK {
3  /**
4  * @details <b>send an email.</b>
5  *
6  * handles the email functions. main method is<br>
7  * <i>Example:</i>
8  * <code><?php YAWK\email::sendEmail($email_from, $email_to, $email_cc, $email_subject, $email_message); ?></code>
9  * Call this anytime when you need to send an email.
10  * <p><i>Class covers both, backend & frontend functionality.
11  * See Methods Summary for Details!</i></p>
12  *
13  * @author Daniel Retzl <[email protected]>
14  * @copyright 2009-2015 Daniel Retzl yawk.io
15  * @license https://opensource.org/licenses/MIT
16  * @version 1.0.0
17  * @brief Email class serve function sendEmail() to send email
18  */
19  class email
20  {
21 
22  /**
23  * @brief send an email
24  * @param string $email_from
25  * @param string $email_to
26  * @param string $email_cc
27  * @param string $email_subject
28  * @param string $email_message
29  * @return bool
30  */
31  static function sendEmail($email_from, $email_to, $email_cc, $email_subject, $email_message)
32  {
33  /* SEND EMAIL WITH GIVEN PARAMS */
34 
35  /* trim fields */
36  $email_from = trim($email_from);
37  $email_to = trim($email_to);
38  $email_cc = trim($email_cc);
39  $email_subject = trim($email_subject);
40  $email_message = trim($email_message);
41 
42  if (!isset($email_cc) || (empty($email_cc)))
43  {
44  $email_cc = false;
45  }
46 
47  /* validate email_to adress with regex */
48  $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
49  if (!preg_match($email_exp, $email_from)) {
50  // echo 'Die Emailadresse scheint nicht korrekt zu sein. Tippfehler?<br /><br /><br />';
51  // exit;
52  }
53 
54  /* build email header */
55  $headers = 'From: ' . $email_from . "\r\n" .
56  'Reply-To: ' . $email_from . "\r\n" .
57  'X-Mailer: PHP/' . phpversion();
58 
59  if ($email_cc === TRUE)
60  {
61  /* send email to website admin */
62  $sent = @mail($email_to, $email_subject, $email_message, $headers);
63  /* send email copy to user */
64  $sent = @mail($email_from, $email_subject, $email_message, $headers);
65  }
66  else
67  {
68  /* just send email to website admin */
69  $sent = @mail($email_to, $email_subject, $email_message, $headers);
70  }
71  if ($sent)
72  {
73  return true;
74  }
75  else
76  {
77  // sending failed
78  /*
79  if(!isset($db) || (empty($db)))
80  {
81  $db = new \YAWK\db();
82  }
83  \YAWK\sys::setSyslog($db, 15, 1, "send email to $email_to failed", 0, 0, 0, 0);
84  */
85  return false;
86  }
87 
88  } /* end function sendEmail(); */
89  } /* end class Email */
90 }
Email class serve function sendEmail() to send email.
Definition: email.php:20
static sendEmail($email_from, $email_to, $email_cc, $email_subject, $email_message)
send an email
Definition: email.php:31
This class serves methods to create backup from files.
Definition: AdminLTE.php:2