addStringAttachment() public method

This method can be used to attach ascii or binary data, such as a BLOB record from a database.
public addStringAttachment ( string $string, string $filename, string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : void
$string string String attachment data.
$filename string Name of the attachment.
$encoding string File encoding (see $Encoding).
$type string File extension (MIME) type.
$disposition string Disposition to use
return void
Example #1
0
 /**
  * Simple plain string attachment test.
  */
 public function testPlainStringAttachment()
 {
     $this->Mail->Body = 'Here is the text body';
     $this->Mail->Subject .= ': Plain + StringAttachment';
     $sAttachment = 'These characters are the content of the ' . "string attachment.\nThis might be taken from a " . 'database or some other such thing. ';
     $this->Mail->addStringAttachment($sAttachment, 'string_attach.txt');
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
 }
Example #2
0
 /**
  * @param $file
  * @param $nameattachment
  * @return $this
  * @throws \phpmailerException
  */
 public function AddAttachment($file, $nameattachment)
 {
     if ($this->isUrl($file)) {
         $this->mail->addStringAttachment(file_get_contents($file), $nameattachment);
     } else {
         $this->mail->AddAttachment($file, $nameattachment);
     }
     return $this;
 }
 /**
  * 快捷发送一封邮件
  * @param string $to 收件人
  * @param string $sub 邮件主题
  * @param string $msg 邮件内容(HTML)
  * @param array $att 附件,每个键为文件名称,值为附件内容(可以为二进制文件),例如array('a.txt' => 'abcd' , 'b.png' => file_get_contents('x.png'))
  * @return bool 成功:true 失败:错误消息
  */
 public static function mail($to, $sub = '无主题', $msg = '无内容', $att = array())
 {
     if (defined("SAE_MYSQL_DB") && class_exists('SaeMail')) {
         $mail = new SaeMail();
         $options = array('from' => option::get('mail_name'), 'to' => $to, 'smtp_host' => option::get('mail_host'), 'smtp_port' => option::get('mail_port'), 'smtp_username' => option::get('mail_smtpname'), 'smtp_password' => option::get('mail_smtppw'), 'subject' => $sub, 'content' => $msg, 'content_type' => 'HTML');
         $mail->setOpt($options);
         $ret = $mail->send();
         if ($ret === false) {
             return 'Mail Send Error: #' . $mail->errno() . ' - ' . $mail->errmsg();
         } else {
             return true;
         }
     } else {
         $From = option::get('mail_name');
         if (option::get('mail_mode') == 'SMTP') {
             $Host = option::get('mail_host');
             $Port = intval(option::get('mail_port'));
             $SMTPAuth = (bool) option::get('mail_auth');
             $Username = option::get('mail_smtpname');
             $Password = option::get('mail_smtppw');
             $Nickname = option::get('mail_yourname');
             if (option::get('mail_ssl') == '1') {
                 $SSL = true;
             } else {
                 $SSL = false;
             }
             $mail = new SMTP($Host, $Port, $SMTPAuth, $Username, $Password, $SSL);
             $mail->att = $att;
             if ($mail->send($to, $From, $sub, $msg, $Nickname)) {
                 return true;
             } else {
                 return $mail->log;
             }
         } else {
             $name = option::get('mail_yourname');
             $mail = new PHPMailer();
             $mail->setFrom($From, $name);
             $mail->addAddress($to);
             $mail->Subject = $sub;
             $mail->msgHTML($msg);
             $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
             foreach ($att as $n => $d) {
                 $mail->addStringAttachment($d, "=?UTF-8?B?" . base64_encode($n) . "?=", 'base64', get_mime(get_extname($n)));
             }
             if (!$mail->send()) {
                 return $mail->ErrorInfo;
             } else {
                 return true;
             }
         }
     }
 }
Example #4
0
 public function sendMail($config, $SetFrom, $addAddress, $AddCC, $subject, $message, $addStringAttachment)
 {
     $mail = new PHPMailer(true);
     $mail->IsSMTP();
     try {
         $mail->Timeout = 3600;
         $mail->SMTPDebug = 0;
         $mail->Debugoutput = 'html';
         $mail->SMTPSecure = 'ssl';
         $mail->Host = $config['host'];
         $mail->SMTPAuth = true;
         $mail->Host = $config['host'];
         $mail->Port = $config['port'];
         $mail->Username = $config['user'];
         $mail->Password = $config['pass'];
         $mail->SetFrom($SetFrom['email'], $SetFrom['name']);
         foreach ($addAddress as $reply) {
             $mail->AddAddress($reply['email'], $reply['name']);
         }
         foreach ($AddCC as $cc) {
             $mail->AddCC($cc['email'], $cc['name']);
         }
         foreach ($addStringAttachment as $cc) {
             $mail->addStringAttachment($addStringAttachment['base64'], $addStringAttachment['name'], 'base64', 'application/' . $addStringAttachment['ext']);
         }
         $mail->Subject = $subject;
         $mail->AltBody = 'To view the message, please use an HTML compatible email viewer !';
         $mail->MsgHTML($this->config->email->header . $message . $this->config->email->header);
         $mail->Send();
         return true;
     } catch (phpmailerException $e) {
         echo $e->errorMessage();
         //Pretty error messages from PHPMailer
         return false;
     } catch (Exception $e) {
         echo $e->getMessage();
         //Boring error messages from anything else!
         return false;
     }
 }
Example #5
0
 /**
  * Send an email
  * 
  * @param string $from        Self explanatory
  * @param string $to          Self explanatory
  * @param string $subject     Self explanatory
  * @param string $text        Self explanatory
  * @param string $html        Self explanatory
  * @param array  $attachments Self explanatory
  * 
  * @return boolean
  */
 function send($from = "", $to = "", $subject = "", $text = "", $html = "", $attachments = array())
 {
     /*
             |--------------
             |  PHPMailer
             |--------------
     */
     if ($this->emailType == 'phpmailer') {
         require_once "PHPMailerAutoload.php";
         $email = new PHPMailer();
         // SMTP support
         if ($this->use_smtp) {
             $email->isSMTP();
             $email->Host = $this->smtp_host;
             if ($this->smtp_encryption != 'none') {
                 $email->SMTPSecure = $this->smtp_encryption;
             }
             $email->SMTPAuth = $this->use_smtp_auth;
             if ($this->use_smtp_auth) {
                 $email->Username = $this->smtp_username;
                 $email->Password = $this->smtp_password;
             }
         }
         // Meta
         $email->CharSet = 'UTF-8';
         // WSXELE-1067: Force UTF-8
         $email->Subject = $subject;
         $email->From = $from;
         $email->FromName = $from;
         $email->addAddress($to, $to);
         // Content
         $email->isHTML(true);
         $email->Body = $this->header . $this->styleHTML($html) . $this->footer;
         $email->AltBody = $text;
         // Attachments
         foreach ($attachments as $file) {
             if (isset($file['name']) && isset($file['content']) && isset($file['mime'])) {
                 $email->addStringAttachment($file['content'], $file['name'], 'base64', $file['mime'], 'attachment');
             }
         }
         if (!$email->send()) {
             $this->registerLog($email->ErrorInfo);
             return false;
         }
         return true;
     }
     /*
             |--------------
             |  WSX5 class
             |--------------
     */
     $email = new imEMail($from, $to, $subject, "utf-8");
     $email->setExpose($this->exposeWsx5);
     $email->setText($text);
     $email->setHTML($this->header . $this->styleHTML($html) . $this->footer);
     $email->setStandardType($this->emailType);
     foreach ($attachments as $a) {
         if (isset($a['name']) && isset($a['content']) && isset($a['mime'])) {
             $email->attachFile($a['name'], $a['content'], $a['mime']);
         }
     }
     if (!$email->send()) {
         $this->registerLog("Cannot send email with internal script");
         return false;
     }
     return true;
 }
Example #6
0
function create_event()
{
    if ($_POST['submit']) {
        $user_name = $_POST['user_name'];
        $user_email = $_POST['user_email'];
        $event_title = str_replace('\\"', '"', $_POST['event_title']);
        if ($_POST['showcase_day'] != '') {
            $showcase_day = $_POST['showcase_day'];
        } else {
            $showcase_day = 'today';
        }
        //echo 'SHOWCASE DAY: '.$showcase_day;
        $showcase_day = strtotime($showcase_day);
        $showcase_day = date("Y-m-d", $showcase_day);
        $submission_date = $_POST['submission_date'];
        $description = $_POST['description'];
        $type = $_POST['type_of_event'];
        include '../../../inc/connection.php';
        // Insert into database
        $sql = "INSERT INTO schedule (user_name, event_title, showcase_day, type, description) VALUES ('{$user_name}','{$event_title}','{$showcase_day}', '{$type}', '{$description}')";
        if (mysqli_query($con, $sql)) {
            $email_subject = '[EVENT] ' . $user_name . ' - "' . $event_title . '" was Received!';
            $email_body = 'Thank you for submitting your music to FREELABEL Studios! We are a collective of producers, designers, and musicians dedicated to producing the highest quality exclusive platform to launch new brands to an audience averaging at <u>8.2+ Million Impressions each month.</u> You will be the branded product behind the impression we make to the world.<br><br>You will need to complete your registration by creating your account at http://freelabel.net/submit/ to get booked on any of the upcoming projects, publications, interviews, & radio showcases on the FREELABEL Radio, Magazine, & TV Network. Feel free to give us a call or email if you have any questions.';
            $email_body = 'Your Event has been submitted and will be reviewed for approval. If you have any questions regarding the status of your event, feel free to contact us at 347-994-0267<BR><BR> Thank you!';
            $body_template = '					<head>
											<style>
															html{
																width:100%;
															}
																body {
																	//background-image:url("' . $uploaded_file_path_http . '");
																	background-size:auto 100%;
																	background-position:center center;
																	background-color:#FE3F44;
																	color:#e3e3e3;
																	padding:0%;
																	margin:0%;
																	text-align:center;
																}
																#para_text {
																margin:1% auto;
																padding:1% 2%;
																font-size:100%;
															}
															#submission_info {
																background-color:#e3e3e3;
																color:#000000;
																width:90%;
																margin:auto;
																padding:2%;
																border-radius:10px;
															}
															#submission_info table, #submission_info tr,#submission_info td {
																margin:auto;
																color:#000;
															}
															a {
																//color:#FE3F44;
																color:#303030;
															}
															#email_photo {
															max-width:500px;
															margin:1% 0 3% 0;
															box-shadow:0px 0px 5px #303030;
														}
														#signature_block {
														margin: 4% auto;
														font-size:80%;

													}
												</style>
												</head>
												<body>
													<img style="width:250px" src="http://freelabel.net/images/FREELABELLOGO.gif"><br>
													<img style="width:250px" src="http://freelabel.net/images/flheadblack.png"><br>

													<div id="para_text">
														<h1>' . $email_subject . '</h1>

														' . $email_body . "\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<hr>\n\t\t\t\t\t\t\t\t\t\t\t\t" . '<h2>EVENT DETAILS:</h2>
														<div id="submission_info">
															<table>
																<tr>
																	<td>TITLE:</td>
																	<td>' . $event_title . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>DATE:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $showcase_day . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>TYPE:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $type . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>DESCRIPTION:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $description . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>EMAIL:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $user_email . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br><br>\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div id='signature_block'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<u>FREELABEL ADMIN</u>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<br>c: (347) 994-0267<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\te: info@FREELABEL.net\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\nFREELABEL.net\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t</body>";
            $stafflist = array($user_email);
            //foreach ($stafflist as $admin) {
            include '../../../mailer/PHPMailerAutoload.php';
            //Create a new PHPMailer instance
            $mail = new PHPMailer();
            // Set PHPMailer to use the sendmail transport
            $mail->isSendmail();
            //Set who the message is to be sent from
            $mail->setFrom('*****@*****.**', 'FREELABEL Studios');
            //Set an alternative reply-to address
            $mail->addReplyTo('*****@*****.**', 'FREELABEL Studios');
            //Set the subject line
            $mail->Subject = $email_subject;
            //Read an HTML message body from an external file, convert referenced images to embedded,
            //convert HTML into a basic plain-text alternative body
            $mail->msgHTML($body_template);
            //Replace the plain text body with one created manually
            $mail->AltBody = $body_template;
            //Attach an image file
            //$mail->addAttachment('images/phpmailer_mini.png');
            //send the message, check for errors
            //foreach ($stafflist as $admin) { //This iterator syntax only works in PHP 5.4+
            $admin = "*****@*****.**";
            $mail->addAddress($admin, 'FREELABEL BOOKING');
            if (!empty($row['photo'])) {
                $mail->addStringAttachment($row['photo'], 'YourPhoto.jpg');
                //Assumes the image data is stored in the DB
            }
            if (!$mail->send()) {
                echo "Mailer Error (" . str_replace("@", "&#64;", $admin) . ') ' . $mail->ErrorInfo . '<br />';
                break;
                //Abandon sending
            } else {
                echo "Message sent to: " . $admin . "!<br>";
                //echo "<br><br><br><br>".$body_template.'<br><br>';
                //echo "Message sent to :" . $admin . ' (' . str_replace("@", "&#64;", $admin) . ')<br />';
            }
            // Clear all addresses and attachments for next loop
            $mail->clearAddresses();
            $mail->clearAttachments();
            //} // foreach END
            // end of sending email
            /*echo '<style>
            		html {
            		color:#fff;
            		background-color:#303030;
            		margin:10%;
            		font-size:300%;
            		font-family:sans-serif;
            		}
            		</style>';*/
            echo "Your Event has been submitted and will be reviewed for confirmation. Please stay updated!<br><br>Your Requested Event: <p id='sub_label' >" . $event_title . '<br>On a ';
            //echo $showcase_day."</p><a href='http://freelabel.net/submit/'>Return to Dashboard</a><br><br><br><br><br><br>";
            //echo '<script>
            //		window.location.assign("http://freelabel.net/?ctrl=booking");
            //	</script>';
            exit;
        } else {
            echo "Error creating database entry: " . mysqli_error($con);
        }
    }
}
Example #7
0
function sendEmail($data = array('recipient' => '', 'toName' => '', 'subject' => '', 'isHTML' => 0, 'html' => '', 'text' => '', 'attach' => array(), 'from' => '', 'fromName' => '', 'sender' => '', 'stringAttach' => array()))
{
    // used to send a standardized email message
    global $phpwcms;
    $mailInfo = array(0 => false, 1 => '');
    $sendTo = array();
    $from = empty($data['from']) || !is_valid_email($data['from']) ? $phpwcms['SMTP_FROM_EMAIL'] : $data['from'];
    $sender = empty($data['sender']) || !is_valid_email($data['sender']) ? $from : $data['sender'];
    $fromName = empty($data['fromName']) ? '' : cleanUpForEmailHeader($data['fromName']);
    $toName = empty($data['toName']) ? '' : cleanUpForEmailHeader($data['toName']);
    $subject = empty($data['subject']) ? 'Email sent by phpwcms' : cleanUpForEmailHeader($data['subject']);
    if (empty($data['html'])) {
        $data['html'] = '';
        $data['isHTML'] = 0;
    } elseif (empty($data['isHTML'])) {
        $data['isHTML'] = 0;
    } else {
        $data['isHTML'] = 1;
    }
    if (empty($data['text'])) {
        $data['text'] = '';
    }
    if (!is_array($data['recipient'])) {
        $recipient = str_replace(' ', '', trim($data['recipient']));
        $recipient = str_replace(',', ';', $recipient);
        $recipient = str_replace(' ', '', $recipient);
        $recipient = explode(';', $recipient);
    } else {
        $recipient = $data['recipient'];
    }
    if (is_array($recipient) && count($recipient)) {
        foreach ($recipient as $value) {
            if (is_valid_email($value)) {
                $sendTo[] = $value;
            }
        }
    }
    if (count($sendTo)) {
        require_once PHPWCMS_ROOT . '/include/inc_ext/phpmailer/PHPMailerAutoload.php';
        $mail = new PHPMailer();
        $mail->Mailer = $phpwcms['SMTP_MAILER'];
        $mail->Host = $phpwcms['SMTP_HOST'];
        $mail->Port = $phpwcms['SMTP_PORT'];
        if ($phpwcms['SMTP_AUTH']) {
            $mail->SMTPAuth = 1;
            $mail->Username = $phpwcms['SMTP_USER'];
            $mail->Password = $phpwcms['SMTP_PASS'];
        }
        if (!empty($phpwcms['SMTP_SECURE'])) {
            $mail->SMTPSecure = $phpwcms['SMTP_SECURE'];
        }
        if (!empty($phpwcms['SMTP_AUTH_TYPE'])) {
            $mail->AuthType = $phpwcms['SMTP_AUTH_TYPE'];
            if ($phpwcms['SMTP_AUTH_TYPE'] === 'NTLM') {
                if (!empty($phpwcms['SMTP_REALM'])) {
                    $mail->Realm = $phpwcms['SMTP_REALM'];
                }
                if (!empty($phpwcms['SMTP_WORKSTATION'])) {
                    $mail->Workstation = $phpwcms['SMTP_WORKSTATION'];
                }
            }
        }
        $mail->CharSet = $phpwcms["charset"];
        $mail->isHTML($data['isHTML']);
        $mail->Subject = $data['subject'];
        if ($data['isHTML']) {
            if ($data['text'] != '') {
                $mail->AltBody = $data['text'];
            }
            $mail->Body = $data['html'];
        } else {
            $mail->Body = $data['text'];
        }
        if (!$mail->setLanguage($phpwcms['default_lang'], PHPWCMS_ROOT . '/include/inc_ext/phpmailer/language/')) {
            $mail->setLanguage('en', PHPWCMS_ROOT . '/include/inc_ext/phpmailer/language/');
        }
        $mail->From = $from;
        $mail->FromName = $fromName;
        $mail->Sender = $sender;
        $mail->addAddress($sendTo[0], $toName);
        unset($sendTo[0]);
        if (is_array($sendTo) && count($sendTo)) {
            foreach ($sendTo as $value) {
                $mail->addBCC($value);
            }
        }
        if (isset($data['attach']) && is_array($data['attach']) && count($data['attach'])) {
            foreach ($data['attach'] as $attach_file) {
                $mail->addAttachment($attach_file);
            }
        }
        if (isset($data['stringAttach']) && is_array($data['stringAttach']) && count($data['stringAttach'])) {
            $attach_counter = 1;
            foreach ($data['stringAttach'] as $attach_string) {
                if (is_array($attach_string) && !empty($attach_string['data'])) {
                    $attach_string['filename'] = empty($attach_string['filename']) ? 'attachment_' . $attach_counter : $attach_string['filename'];
                    $attach_string['mime'] = empty($attach_string['mime']) ? 'application/octet-stream' : $attach_string['mime'];
                    $attach_string['encoding'] = empty($attach_string['encoding']) ? 'base64' : $attach_string['encoding'];
                    $mail->addStringAttachment($attach_string['data'], $attach_string['filename'], $attach_string['encoding'], $attach_string['mime']);
                    $attach_counter++;
                }
            }
        }
        if (!$mail->send()) {
            $mailInfo[0] = false;
            $mailInfo[1] = $mail->ErrorInfo;
        } else {
            $mailInfo[0] = true;
        }
        unset($mail);
    } else {
        $mailInfo[0] = false;
        $mailInfo[1] = 0;
        //means no recipient
    }
    return $mailInfo;
}
 //Same body for all messages, so set this before the sending loop
 //If you generate a different body for each recipient (e.g. you're using a templating system),
 //set it inside the loop
 $mail->msgHTML($body);
 //msgHTML also sets AltBody, but if you want a custom one, set it afterwards
 $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
 //Connect to the database and select the recipients from your mailing list that have not yet been sent to
 //You'll need to alter this to match your database
 $mysql = mysqli_connect(DBHOST, DBUSER, DBPASSWORD);
 mysqli_select_db($mysql, DBNAME);
 $result = mysqli_query($mysql, 'SELECT full_name, email, photo FROM mailinglist WHERE sent = false');
 foreach ($result as $row) {
     //This iterator syntax only works in PHP 5.4+
     $mail->addAddress($row['email'], $row['full_name']);
     if (!empty($row['photo'])) {
         $mail->addStringAttachment($row['photo'], 'YourPhoto.jpg');
         //Assumes the image data is stored in the DB
     }
     if (!$mail->send()) {
         echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
         break;
         //Abandon sending
     } else {
         echo "Message sent to :" . $row['full_name'] . ' (' . str_replace("@", "&#64;", $row['email']) . ')<br />';
         //Mark it as sent in the DB
         mysqli_query($mysql, "UPDATE mailinglist SET sent = true WHERE email = '" . mysqli_real_escape_string($mysql, $row['email']) . "'");
     }
     // Clear all addresses and attachments for next loop
     $mail->clearAddresses();
     $mail->clearAttachments();
 }
Example #9
0
function save_lead()
{
    if ($_POST['submit']) {
        $user_name = $_POST['user_name'];
        if ($user_name == '') {
            $user_name = 'pathways';
        }
        $lead_name = $_POST['lead_name'];
        $lead_twitter = trim($_POST['lead_twitter']);
        $lead_phone = trim($_POST['lead_phone']);
        $lead_email = trim($_POST['lead_email']);
        $lead_twitter_noat = str_replace('@', '', $lead_twitter);
        $follow_up_date_time = strtotime($_POST['follow_up_date']);
        $follow_up_date = date('Y:m:d', $follow_up_date_time);
        $entry_date = date('Y-m-d H:i');
        include '../../../inc/connection.php';
        if (mysqli_fetch_array($result) == false) {
            echo '<p id="joinbutton">';
            echo 'You have no Leads :(.
				</p>';
        }
        // Insert into database
        $sql = "INSERT INTO leads (user_name, lead_name, lead_twitter, follow_up_date, entry_date, lead_phone, lead_email) VALUES ('{$user_name}','{$lead_name}','{$lead_twitter}','{$follow_up_date}','{$entry_date}','{$lead_phone}','{$lead_email}')";
        if (mysqli_query($con, $sql)) {
            $follow_up_date = date('l, M/j/Y @ h:i A', $follow_up_date_time);
            // NOTIFICATIONS
            $email_subject = '[LEAD] ' . $lead_twitter . ' - "' . $lead_name . '" was Received!';
            $email_body = 'We have an new lead.<br><br>' . $lead_name . '<br><br><hr><br>';
            $email_body .= 'Thank you for submitting your music to FREELABEL Studios! We are a collective of producers, designers, and musicians dedicated to producing the highest quality exclusive platform to launch new brands to an audience averaging at <u>8.2+ Million Impressions each month.</u> You will be the branded product behind the impression we make to the world.<br><br>You will need to complete your registration by creating your account at http://freelabel.net/submit/ to get booked on any of the upcoming projects, publications, interviews, & radio showcases on the FREELABEL Radio, Magazine, & TV Network. Feel free to give us a call or email if you have any questions.';
            $body_template = '								<style>
															html{
																width:100%;
															}
																body {
																	//background-image:url("' . $uploaded_file_path_http . '");
																	background-size:auto 100%;
																	background-position:center center;
																	background-color:#FE3F44;
																	color:#e3e3e3;
																	padding:0%;
																	margin:0%;
																	text-align:center;
																}
																#para_text {
																margin:1% auto;
																padding:1% 2%;
																font-size:100%;
															}
															#submission_info {
																background-color:#e3e3e3;
																color:#000000;
																width:90%;
																margin:auto;
																padding:2%;
																border-radius:10px;
															}
															#submission_info table, #submission_info tr,#submission_info td {
																margin:auto;
																color:#000;
															}
															a {
																//color:#FE3F44;
																color:#303030;
															}
															#email_photo {
															max-width:500px;
															margin:1% 0 3% 0;
															box-shadow:0px 0px 5px #303030;
														}
														#signature_block {
														margin: 4% auto;
														font-size:80%;

													}
												</style>
												<body>
													<img style="width:250px" src="http://freelabel.net/images/FREELABELLOGO.gif"><br>
													<img style="width:250px" src="http://freelabel.net/images/flheadblack.png"><br>

													<div id="para_text">
														<h1>' . $email_subject . '</h1>

														' . $email_body . "\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<hr>\n\t\t\t\t\t\t\t\t\t\t\t\t" . '<h2>LEAD INFORMATION:</h2>
														<div id="submission_info">
															<table>
																<tr>
																	<td>COMMENTS:</td>
																	<td>' . $lead_name . '</td>
																</tr>
																<tr>
																	<td>PHONE:</td>
																	<td>' . $lead_phone . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>FOLLOW UP // ENTRY DATE:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $follow_up_date . " // " . $entry_date . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>TWITTER:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $lead_twitter . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>EMAIL:</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $lead_email . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br><br>\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div id='signature_block'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<u>FREELABEL Account Executive</u>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<br>c: (323) 601-8111<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\te: info@FREELABEL.net\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\nFREELABEL.net\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t</body>";
            $stafflist = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
            //foreach ($stafflist as $admin) {
            include '../../../mailer/PHPMailerAutoload.php';
            //Create a new PHPMailer instance
            $mail = new PHPMailer();
            // Set PHPMailer to use the sendmail transport
            $mail->isSendmail();
            //Set who the message is to be sent from
            $mail->setFrom('*****@*****.**', 'FL SALES');
            //Set an alternative reply-to address
            $mail->addReplyTo('*****@*****.**', 'Sales Administration');
            //Set the subject line
            $mail->Subject = $email_subject;
            //Read an HTML message body from an external file, convert referenced images to embedded,
            //convert HTML into a basic plain-text alternative body
            $mail->msgHTML($body_template);
            //Replace the plain text body with one created manually
            $mail->AltBody = $body_template;
            //Attach an image file
            //$mail->addAttachment('images/phpmailer_mini.png');
            //send the message, check for errors
            foreach ($stafflist as $admin) {
                //This iterator syntax only works in PHP 5.4+
                $mail->addAddress($admin, 'FREELABEL SUBMISSIONS');
                if (!empty($row['photo'])) {
                    $mail->addStringAttachment($row['photo'], 'YourPhoto.jpg');
                    //Assumes the image data is stored in the DB
                }
                if (!$mail->send()) {
                    echo "Mailer Error (" . str_replace("@", "&#64;", $admin) . ') ' . $mail->ErrorInfo . '<br />';
                    break;
                    //Abandon sending
                } else {
                    echo "Message sent to: " . $admin . "!<br>";
                    //echo "<br><br><br><br>".$body_template.'<br><br>';
                    echo "Message sent to :" . $admin . ' (' . str_replace("@", "&#64;", $admin) . ')<br />';
                }
                // Clear all addresses and attachments for next loop
                $mail->clearAddresses();
                $mail->clearAttachments();
            }
            echo "Entry Created Successfully! ";
            echo "<script>\n\t\t\t\t\t\t\t\t\t\t\tfunction newDoc()\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\twindow.location.assign(\"http://freelabel.net/?ctrl=leads#add\")\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tnewDoc()\n\t\t\t\t\t\t\t\t\t\t\t</script>";
            echo '<style>
					html {
					color:#fff;
					background-color:#303030;
					margin:10%;
					font-size:300%;
					font-family:sans-serif;
					}
					</style>';
            echo "Your LEAD has been Saved. Please stay updated!<br><br>Your Lead: <p id='sub_label' >" . $lead_name . '<br>TWITTER: ';
            echo $lead_twitter . " and you must follow up on: " . $follow_up_date . "</p><a href='http://freelabel.net/submit/#leads'>Return to Dashboard</a><br><br><br><br><br><br>";
        } else {
            echo "Error creating database entry: " . mysqli_error($con);
        }
    }
}
function sendEmail($recipient, $aliasNames = '', $from = '佳诚装饰', $subject, $body, $attachement = null)
{
    date_default_timezone_set('PRC');
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug = 2;
    $mail->Debugoutput = 'html';
    $mail->Host = "smtp.sina.com";
    $mail->Port = "465";
    $mail->SMTPSecure = "ssl";
    $mail->SMTPAuth = true;
    $mail->Username = "******";
    $mail->Password = "******";
    $mail->Priority = 1;
    $mail->Charset = 'utf-8';
    $mail->Encoding = 'base64';
    $mail->From = '*****@*****.**';
    $mail->FromName = trim($from) == '佳诚装饰' ? '' : $from;
    $mail->Timeout = 30;
    if ($recipient == null) {
        echo "recipient should not be null !<br />\n";
        die;
    }
    if (is_string($recipient) && contains($recipient, ',')) {
        $recipient = explode(',', $recipient);
    }
    if (is_string($aliasNames) && contains($aliasNames, ',')) {
        $aliasNames = explode(',', $aliasNames);
    }
    if (is_string($recipient) && contains($recipient, '@')) {
        $mail->addAddress($recipient, $aliasNames);
    }
    if (is_array($recipient)) {
        $recipient = array_merge($recipient);
        $count = count($recipient);
        $aliasNames = is_array($aliasNames) ? array_merge($aliasNames) : array();
        for ($i = 0; $i < $count; $i++) {
            $address = $recipient[$i];
            $name = isset($aliasNames[$i]) ? $aliasNames[$i] : '';
            if (is_string($address) && contains($address, '@')) {
                echo "send mail to {$address} as {$name} <br />\n";
                $mail->addAddress($address, $name);
            }
        }
    }
    // $mail->addAddress('*****@*****.**','IT_Diego');
    // $mail->addAddress('*****@*****.**','IT_Alex');
    $mail->isHTML(true);
    // Set email format to HTML
    if ($attachement != null) {
        $mail->addStringAttachment($attachement['content'], $attachement['name']);
    }
    $mail->Subject = "【佳诚装饰】 {$subject}";
    $mail->Body = $body;
    $mail->AltBody = "";
    if (!$mail->send()) {
        echo "Message could not be sent.<br />\n";
        echo "Mailer Error: " . $mail->ErrorInfo . "<br />\n";
    } else {
        echo "Message has been sent<br />\n";
    }
    $mail->smtpClose();
}
Example #11
0
 /**
  * Send an email
  * 
  * @param string $from        Self explanatory
  * @param string $to          Self explanatory
  * @param string $subject     Self explanatory
  * @param string $text        Self explanatory
  * @param string $html        Self explanatory
  * @param array  $attachments Self explanatory
  * 
  * @return boolean
  */
 function send($from = "", $to = "", $subject = "", $text = "", $html = "", $attachments = array())
 {
     /*
             |--------------
             |  PHPMailer
             |--------------
     */
     if ($this->emailType == 'phpmailer') {
         require_once "PHPMailerAutoload.php";
         $email = new PHPMailer();
         // SMTP support
         if ($this->use_smtp) {
             $email->isSMTP();
             $email->Host = $this->smtp_host;
             $email->Port = $this->smtp_port;
             if ($this->smtp_encryption != 'none') {
                 $email->SMTPSecure = $this->smtp_encryption;
             }
             $email->SMTPAuth = $this->use_smtp_auth;
             if ($this->use_smtp_auth) {
                 $email->Username = $this->smtp_username;
                 $email->Password = $this->smtp_password;
             }
         }
         // Meta
         $email->CharSet = 'UTF-8';
         // WSXELE-1067: Force UTF-8
         $email->Subject = $subject;
         $email->From = addressFromEmail($from);
         $email->FromName = nameFromEmail($from);
         // WSXELE-1120: Split the email addresses if necessary
         $to = str_replace(";", ",", $to);
         // Make sure it works for both "," and ";" separators
         foreach (explode(",", $to) as $addr) {
             // WSXELE-1157: Provide support for the format John Doe <*****@*****.**>
             $email->addAddress(addressFromEmail($addr), nameFromEmail($addr));
         }
         // Content
         $email->isHTML(true);
         $email->Body = $this->header . $this->styleHTML($html) . $this->footer;
         $email->AltBody = $text;
         // Attachments
         foreach ($attachments as $file) {
             if (isset($file['name']) && isset($file['content']) && isset($file['mime'])) {
                 $email->addStringAttachment($file['content'], $file['name'], 'base64', $file['mime'], 'attachment');
             }
         }
         if (!$email->send()) {
             $this->registerLog($email->ErrorInfo);
             return false;
         }
         return true;
     }
     /*
             |--------------
             |  WSX5 class
             |--------------
     */
     $email = new imEMail($from, $to, $subject, "utf-8");
     $email->setExpose($this->exposeWsx5);
     $email->setText($text);
     $email->setHTML($this->header . $this->styleHTML($html) . $this->footer);
     $email->setStandardType($this->emailType);
     foreach ($attachments as $a) {
         if (isset($a['name']) && isset($a['content']) && isset($a['mime'])) {
             $email->attachFile($a['name'], $a['content'], $a['mime']);
         }
     }
     if (!$email->send()) {
         $this->registerLog("Cannot send email with internal script");
         return false;
     }
     return true;
 }
Example #12
-2
function phorum_smtp_send_messages($data)
{
    global $PHORUM;
    $addresses = $data['addresses'];
    $subject = $data['subject'];
    $message = $data['body'];
    $num_addresses = count($addresses);
    $settings = $PHORUM['smtp_mail'];
    $settings['auth'] = empty($settings['auth']) ? false : true;
    if ($num_addresses > 0) {
        try {
            require_once "./mods/smtp_mail/phpmailer/class.phpmailer.php";
            $mail = new PHPMailer();
            $mail->PluginDir = "./mods/smtp_mail/phpmailer/";
            $mail->CharSet = $PHORUM["DATA"]["CHARSET"];
            $mail->Encoding = $PHORUM["DATA"]["MAILENCODING"];
            $mail->Mailer = "smtp";
            $mail->isHTML(false);
            $mail->From = $PHORUM['system_email_from_address'];
            $mail->Sender = $PHORUM['system_email_from_address'];
            $mail->FromName = $PHORUM['system_email_from_name'];
            if (!isset($settings['host']) || empty($settings['host'])) {
                $settings['host'] = 'localhost';
            }
            if (!isset($settings['port']) || empty($settings['port'])) {
                $settings['port'] = '25';
            }
            $mail->Host = $settings['host'];
            $mail->Port = $settings['port'];
            // set the connection type
            if ($settings['conn'] == 'ssl') {
                $mail->SMTPSecure = "ssl";
            } elseif ($settings['conn'] == 'tls') {
                $mail->SMTPSecure = "tls";
            }
            // smtp-authentication
            if ($settings['auth'] && !empty($settings['username'])) {
                $mail->SMTPAuth = true;
                $mail->Username = $settings['username'];
                $mail->Password = $settings['password'];
            }
            $mail->Body = $message;
            $mail->Subject = $subject;
            // add the newly created message-id
            // in phpmailer as a public var
            $mail->MessageID = $data['messageid'];
            // add custom headers if defined
            if (!empty($data['custom_headers'])) {
                // custom headers in phpmailer are added one by one
                $custom_headers = explode("\n", $data['custom_headers']);
                foreach ($custom_headers as $cheader) {
                    $mail->addCustomHeader($cheader);
                }
            }
            // add attachments if provided
            if (isset($data['attachments']) && count($data['attachments'])) {
                /*
                 * Expected input is an array of
                 *
                 * array(
                 * 'filename'=>'name of the file including extension',
                 * 'filedata'=>'plain (not encoded) content of the file',
                 * 'mimetype'=>'mime type of the file', (optional)
                 * )
                 *
                 */
                foreach ($data['attachments'] as $att_id => $attachment) {
                    $att_type = !empty($attachment['mimetype']) ? $attachment['mimetype'] : 'application/octet-stream';
                    $mail->addStringAttachment($attachment['filedata'], $attachment['filename'], 'base64', $att_type);
                    // try to unset it in the original array to save memory
                    unset($data['attachments'][$att_id]);
                }
            }
            if (!empty($settings['bcc']) && $num_addresses > 3) {
                $bcc = 1;
                $mail->addAddress("undisclosed-recipients:;");
            } else {
                $bcc = 0;
                // lets keep the connection alive - it could be multiple mails
                $mail->SMTPKeepAlive = true;
            }
            foreach ($addresses as $address) {
                if ($bcc) {
                    $mail->addBCC($address);
                } else {
                    $mail->addAddress($address);
                    if (!$mail->send()) {
                        $error_msg = "There was an error sending the message.";
                        $detail_msg = "Error returned was: " . $mail->ErrorInfo;
                        if (function_exists('event_logging_writelog')) {
                            event_logging_writelog(array("source" => "smtp_mail", "message" => $error_msg, "details" => $detail_msg, "loglevel" => EVENTLOG_LVL_ERROR, "category" => EVENTLOG_CAT_MODULE));
                        }
                        if (!isset($settings['show_errors']) || !empty($settings['show_errors'])) {
                            echo $error_msg . "\n";
                            echo $detail_msg;
                        }
                    } elseif (!empty($settings['log_successful'])) {
                        if (function_exists('event_logging_writelog')) {
                            event_logging_writelog(array("source" => "smtp_mail", "message" => "Email successfully sent", "details" => "An email has been sent:\nTo:{$address}\nSubject: {$subject}\nBody: {$message}\n", "loglevel" => EVENTLOG_LVL_INFO, "category" => EVENTLOG_CAT_MODULE));
                        }
                    }
                    // Clear all addresses  for next loop
                    $mail->clearAddresses();
                }
            }
            // bcc needs just one send call
            if ($bcc) {
                if (!$mail->send()) {
                    $error_msg = "There was an error sending the bcc message.";
                    $detail_msg = "Error returned was: " . $mail->ErrorInfo;
                    if (function_exists('event_logging_writelog')) {
                        event_logging_writelog(array("source" => "smtp_mail", "message" => $error_msg, "details" => $detail_msg, "loglevel" => EVENTLOG_LVL_ERROR, "category" => EVENTLOG_CAT_MODULE));
                    }
                    if (!isset($settings['show_errors']) || !empty($settings['show_errors'])) {
                        echo $error_msg . "\n";
                        echo $detail_msg;
                    }
                } elseif (!empty($settings['log_successful'])) {
                    if (function_exists('event_logging_writelog')) {
                        $address_join = implode(",", $addresses);
                        event_logging_writelog(array("source" => "smtp_mail", "message" => "BCC-Email successfully sent", "details" => "An email (bcc-mode) has been sent:\nBCC:{$address_join}\nSubject: {$subject}\nBody: {$message}\n", "loglevel" => EVENTLOG_LVL_INFO, "category" => EVENTLOG_CAT_MODULE));
                    }
                }
            }
            // we have to close the connection with pipelining
            // which is only used in non-bcc mode
            if (!$bcc) {
                $mail->smtpClose();
            }
        } catch (Exception $e) {
            $error_msg = "There was a problem communicating with SMTP";
            $detail_msg = "The error returned was: " . $e->getMessage();
            if (function_exists('event_logging_writelog')) {
                event_logging_writelog(array("source" => "smtp_mail", "message" => $error_msg, "details" => $detail_msg, "loglevel" => EVENTLOG_LVL_ERROR, "category" => EVENTLOG_CAT_MODULE));
            }
            if (!isset($settings['show_errors']) || !empty($settings['show_errors'])) {
                echo $error_msg . "\n";
                echo $detail_msg;
            }
            exit;
        }
    }
    unset($message);
    unset($mail);
    // make sure that the internal mail-facility doesn't kick in
    return 0;
}