本文整理汇总了PHP中PHPMailer::addStringAttachment方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPMailer::addStringAttachment方法的具体用法?PHP PHPMailer::addStringAttachment怎么用?PHP PHPMailer::addStringAttachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPMailer
的用法示例。
在下文中一共展示了PHPMailer::addStringAttachment方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPlainStringAttachment
/**
* 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);
}
示例2: AddAttachment
/**
* @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;
}
示例3: mail
/**
* 快捷发送一封邮件
* @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;
}
}
}
}
示例4: sendMail
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;
}
}
示例5: send
/**
* 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;
}
示例6: create_event
//.........这里部分代码省略.........
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('admin@freelabel.net', 'FREELABEL Studios');
//Set an alternative reply-to address
$mail->addReplyTo('admin@freelabel.net', '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 = "notifications@freelabel.net";
$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("@", "@", $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("@", "@", $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);
}
}
}
示例7: sendEmail
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++;
//.........这里部分代码省略.........
示例8: foreach
//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("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
break;
//Abandon sending
} else {
echo "Message sent to :" . $row['full_name'] . ' (' . str_replace("@", "@", $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();
}
示例9: save_lead
//.........这里部分代码省略.........
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('notifications@freelabel.net', 'sales@freelabel.net', 'request.chiffon@gmail.com');
//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('admin@freelabel.net', 'FL SALES');
//Set an alternative reply-to address
$mail->addReplyTo('admin@freelabel.net', '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("@", "@", $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("@", "@", $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);
}
}
}
示例10: sendEmail
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 = "dqjczs@sina.com";
$mail->Password = "86676688";
$mail->Priority = 1;
$mail->Charset = 'utf-8';
$mail->Encoding = 'base64';
$mail->From = 'dqjczs@sina.com';
$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('674417307@qq.com','IT_Diego');
// $mail->addAddress('547010762@qq.com','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();
}
示例11: send
/**
* 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 <johndoe@email.com>
$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;
}
示例12: phorum_smtp_send_messages
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));
}
//.........这里部分代码省略.........