Jump to content

Recommended Posts

This sendmail code is from Discuz! Board

I have a problem when I wish to send mail to my board member. When I send email to multiple members, member can read other member’s email address. I try to hide the address, then I changed

fputs($fp, "To: ".$email_to."\r\n");

To

fputs($fp, "Bcc: ".$email_to."\r\n");

But then I am facing another problem, member’s email is not showing 'To: xxx@xxx.com', for example. Hotmail will reject these kind of email.

Then I decided to add

fputs($fp, "To: ".$touser."\r\n");   //note that it is touser not email_to

before

fputs($fp, "Bcc: ".$email_to."\r\n");

but it showed the last member’s email address on every member’s email. 'To: last_member@xxx.com', for example insteed of 'To: particular_member@xxx.com.

Finally I found that,

fputs($fp, "Date: ".gmdate('r')."\r\n");

fputs($fp, "To: ".$touser."\r\n");

fputs($fp, "Bcc: ".$email_to."\r\n");

fputs($fp, "Subject: ".$email_subject."\r\n");

fputs($fp, $headers."\r\n");

fputs($fp, "\r\n\r\n");

fputs($fp, "$email_message\r\n.\r\n");

fputs($fp, "QUIT\r\n");

are only tell the email what to show in every member’s email. Even I have looped and updated $touser, the code above is only running 1 time.

So, here is my problem:

Can you help me to modify the original code so that it will send email one by one with every email only show the particular member’s email address on his email.

 

Thank you!!

 

ORIGINAL CODE:

<?php

 

/*

[Discuz!] ©2001-2007 Comsenz Inc.

This is NOT a freeware, use is subject to license terms

 

$RCSfile: sendmail.inc.php,v $

$Revision: 1.16.2.1 $

$Date: 2007/03/21 15:52:38 $

*/

 

if(!defined('IN_DISCUZ')) {

exit('Access Denied');

}

 

@include DISCUZ_ROOT.'./mail_config.inc.php';

@include language('emails');

 

if($sendmail_silent) {

error_reporting(0);

}

 

if(isset($language[$email_subject])) {

eval("\$email_subject = \"".$language[$email_subject]."\";");

}

if(isset($language[$email_message])) {

eval("\$email_message = \"".$language[$email_message]."\";");

}

 

$maildelimiter = !empty($maildelimiter) ? "\r\n" : "\n";

$mailusername = isset($mailusername) ? $mailusername : 1;

 

$email_subject = '=?'.$charset.'?B?'.base64_encode(str_replace("\r", '', str_replace("\n", '', '['.$bbname.'] '.$email_subject))).'?=';

$email_message = chunk_split(base64_encode(str_replace("\r\n.", " \r\n..", str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $email_message)))))));

 

$email_from = $email_from == '' ? '=?'.$charset.'?B?'.base64_encode($bbname)."?= <$adminemail>" : (preg_match('/^(.+?) \<(.+?)\>$/',$email_from, $from) ? '=?'.$charset.'?B?'.base64_encode($from[1])."?= <$from[2]>" : $email_from);

 

foreach(explode(',', $email_to) as $touser) {

$tousers[] = preg_match('/^(.+?) \<(.+?)\>$/',$touser, $to) ? ($mailusername ? '=?'.$charset.'?B?'.base64_encode($to[1])."?= <$to[2]>" : $to[2]) : $touser;

}

$email_to = implode(',', $tousers);

 

$headers = "From: $email_from{$maildelimiter}MIME-Version: 1.0{$maildelimiter}Content-type: text/plain; charset=$charset{$maildelimiter}Content-Transfer-Encoding: base64{$maildelimiter}";

 

if($mailsend == 1 && function_exists('mail')) {

 

@mail($email_to, $email_subject, $email_message, $headers);

 

} elseif($mailsend == 2) {

 

if(!$fp = fsockopen($mailcfg['server'], $mailcfg['port'], $errno, $errstr, 30)) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) CONNECT - Unable to connect to the SMTP server, please check your \"mail_config.inc.php\".", 0);

}

stream_set_blocking($fp, true);

 

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != '220') {

errorlog('SMTP', "$mailcfg[server]:$mailcfg[port] CONNECT - $lastmessage", 0);

}

 

fputs($fp, ($mailcfg['auth'] ? 'EHLO' : 'HELO')." discuz\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 220 && substr($lastmessage, 0, 3) != 250) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) HELO/EHLO - $lastmessage", 0);

}

 

while(1) {

if(substr($lastmessage, 3, 1) != '-' || empty($lastmessage)) {

break;

}

$lastmessage = fgets($fp, 512);

}

 

if($mailcfg['auth']) {

fputs($fp, "AUTH LOGIN\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 334) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) AUTH LOGIN - $lastmessage", 0);

}

 

fputs($fp, base64_encode($mailcfg['auth_username'])."\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 334) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) USERNAME - $lastmessage", 0);

}

 

fputs($fp, base64_encode($mailcfg['auth_password'])."\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 235) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) PASSWORD - $lastmessage", 0);

}

 

$email_from = $mailcfg['from'];

}

 

fputs($fp, "MAIL FROM: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $email_from).">\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 250) {

fputs($fp, "MAIL FROM: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $email_from).">\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 250) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) MAIL FROM - $lastmessage", 0);

}

}

 

$email_tos = array();

foreach(explode(',', $email_to) as $touser) {

$touser = trim($touser);

if($touser) {

fputs($fp, "RCPT TO: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $touser).">\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 250) {

fputs($fp, "RCPT TO: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $touser).">\r\n");

$lastmessage = fgets($fp, 512);

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) RCPT TO - $lastmessage", 0);

}

}

}

 

fputs($fp, "DATA\r\n");

$lastmessage = fgets($fp, 512);

if(substr($lastmessage, 0, 3) != 354) {

errorlog('SMTP', "($mailcfg[server]:$mailcfg[port]) DATA - $lastmessage", 0);

}

 

$headers .= 'Message-ID: <'.gmdate('YmdHs').'.'.substr(md5($email_message.microtime()), 0, 6).rand(100000, 999999).'@'.$_SERVER['HTTP_HOST'].">{$maildelimiter}X-Priority: 3{$maildelimiter}X-Mailer: Discuz! Mailer{$maildelimiter}";

 

fputs($fp, "Date: ".gmdate('r')."\r\n");

fputs($fp, "To: ".$email_to."\r\n");

fputs($fp, "Subject: ".$email_subject."\r\n");

fputs($fp, $headers."\r\n");

fputs($fp, "\r\n\r\n");

fputs($fp, "$email_message\r\n.\r\n");

fputs($fp, "QUIT\r\n");

 

} elseif($mailsend == 3) {

 

ini_set('SMTP', $mailcfg['server']);

ini_set('smtp_port', $mailcfg['port']);

ini_set('sendmail_from', $email_from);

 

@mail($email_to, $email_subject, $email_message, $headers);

 

}

 

?>

 

mail_config.inc.php

<?php

 

/*

[Discuz!] ©2001-2007 Comsenz Inc.

This is NOT a freeware, use is subject to license terms

 

$RCSfile: mail_config5.inc.php,v $

$Revision: 1.1.2.2 $

$Date: 2007/03/21 15:52:04 $

*/

 

// [EN] !ATTENTION! Type 2 & type 3 are only experimental, we do not provide any guarantee or support of this

 

$sendmail_silent = 1; // ignore error reporting, 1=yes, 0=no

 

$mailsend = 2; // sendmail type

// 0=do not send any mails

// 1=send via PHP mail() function and UNIX sendmail

// 2=send via Discuz! SMTP/ESMTP interface

// 3=send via PHP mail() and SMTP(only for win32, do not support ESMTP)

 

$maildelimiter = 1; 0=LF,1=CRLF

 

$mailusername = 1; // include member's name,1=yes, 0=no

 

if($mailsend == 1) {

 

// Send via PHP mail() and UNIX sendmail(no extra configuration)

 

} elseif($mailsend == 2) { // send via Discuz! ESMTP interface

 

$mailcfg['server'] = 'smtp.yourname.com'; // SMTP host address

 

$mailcfg['port'] = '25'; // SMTP port, leave default for most occations

 

$mailcfg['auth'] = 1; // require authentification? 1=yes, 0=no

 

$mailcfg['from'] = 'Discuz! <yourname@yourname.com>'; // mail from (if authentification required, do use local email address of ESMTP server)

 

$mailcfg['auth_username'] = 'username'; // username for authentification

 

$mailcfg['auth_password'] = 'password'; // password for authentification

 

} elseif($mailsend == 3) { // send via PHP mail() and SMTP(only for win32, do not support ESMTP)

 

$mailcfg['server'] = 'smtp.your.com'; // SMTP host address

 

$mailcfg['port'] = '25'; // SMTP port

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/55303-sendmail-problem-with-discuz/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.