123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- <?php
- require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php';
- require_once api_get_path(CONFIGURATION_PATH).'mail.conf.php';
- $regexp_rfc3696 = "^[0-9a-z_\.+-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$";
- function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name="", $sender_email="", $extra_headers="") {
- global $regexp_rfc3696;
- global $platform_email;
- $mail = new PHPMailer();
- $mail->Mailer = $platform_email['SMTP_MAILER'];
- $mail->Host = $platform_email['SMTP_HOST'];
- $mail->Port = $platform_email['SMTP_PORT'];
- $mail->CharSet = $platform_email['SMTP_CHARSET'];
- $mail->WordWrap = 200;
- if($platform_email['SMTP_AUTH'])
- {
- $mail->SMTPAuth = 1;
- $mail->Username = $platform_email['SMTP_USER'];
- $mail->Password = $platform_email['SMTP_PASS'];
- }
- $mail->Priority = 3;
- $mail->AddCustomHeader("Errors-To: ".$platform_email['SMTP_FROM_EMAIL']."");
- $mail->IsHTML(0);
- $mail->SMTPKeepAlive = true;
-
-
-
- if ($sender_email!="")
- {
- $mail->From = $sender_email;
- $mail->Sender = $sender_email;
-
- }
- else
- {
- $mail->From = $platform_email['SMTP_FROM_EMAIL'];
- $mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
-
- }
- if ($sender_name!="")
- {
- $mail->FromName = $sender_name;
- }
- else
- {
- $mail->FromName = $platform_email['SMTP_FROM_NAME'];
- }
- $mail->Subject = $subject;
- $mail->Body = $message;
-
- if(eregi( $regexp_rfc3696, $recipient_email ))
- {
- $mail->AddAddress($recipient_email, $recipient_name);
- }
- if ($extra_headers != ""){
- $mail->AddCustomHeader($extra_headers);
- }
-
- if (!$mail->Send())
- {
-
- return 0;
- }
-
- $mail->ClearAddresses();
- return 1;
- }
- function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = "", $sender_email = "", $extra_headers = null, $data_file = array()) {
- global $regexp_rfc3696;
- global $platform_email;
- $mail = new PHPMailer();
- $mail->Mailer = $platform_email['SMTP_MAILER'];
- $mail->Host = $platform_email['SMTP_HOST'];
- $mail->Port = $platform_email['SMTP_PORT'];
- $mail->CharSet = $platform_email['SMTP_CHARSET'];
- $mail->WordWrap = 200;
- if($platform_email['SMTP_AUTH'])
- {
- $mail->SMTPAuth = 1;
- $mail->Username = $platform_email['SMTP_USER'];
- $mail->Password = $platform_email['SMTP_PASS'];
- }
- $mail->Priority = 3;
- $mail->AddCustomHeader("Errors-To: ".$platform_email['SMTP_FROM_EMAIL']."");
- $mail->IsHTML(0);
- $mail->SMTPKeepAlive = true;
- if (($sender_email != "") && ($sender_name != "")) {
- $mail->AddReplyTo ($sender_email,$sender_name);
- }
-
-
-
- if ($sender_email!="")
- {
- $mail->From = $sender_email;
- $mail->Sender = $sender_email;
-
- }
- else
- {
- $mail->From = $platform_email['SMTP_FROM_EMAIL'];
- $mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
-
- }
- if ($sender_name!="")
- {
- $mail->FromName = $sender_name;
- }
- else
- {
- $mail->FromName = $platform_email['SMTP_FROM_NAME'];
- }
- $mail->Subject = $subject;
- $mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
- $mail->Body = '<html><head></head><body>'.$message.'</body></html>';
-
- if (!empty($data_file)) {
- $mail->AddAttachment($data_file['path'], $data_file['filename']);
- }
-
- if(is_array($recipient_email)) {
- foreach($recipient_email as $dest) {
- if(eregi( $regexp_rfc3696, $dest )) {
- $mail->AddAddress($dest, $recipient_name);
-
- }
- }
- } else {
- if(eregi( $regexp_rfc3696, $recipient_email ))
- {
- $mail->AddAddress($recipient_email, $recipient_name);
- } else {
- return 0;
- }
- }
- if (is_array($extra_headers) && count($extra_headers)>0){
- foreach($extra_headers as $key=>$value)
- {
- switch(strtolower($key)){
- case 'encoding':
- case 'content-transfer-encoding':
- $mail->Encoding = $value;
- break;
- case 'charset':
- $mail->Charset = $value;
- break;
- case 'contenttype':
- case 'content-type':
- $mail->ContentType = $value;
- break;
- default:
- $mail->AddCustomHeader($key.':'.$value);
- break;
- }
- }
- }
-
- $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
-
- if (!$mail->Send())
- {
-
- return 0;
- }
-
- $mail->ClearAddresses();
- return 1;
- }
- ?>
|