From: <rm...@us...> - 2002-09-17 00:55:38
|
Update of /cvsroot/webnotes/webnotes/core In directory usw-pr-cvs1:/tmp/cvs-serv7030/core Modified Files: api.php config_inc.php user_api.php Added Files: email_api.php Log Message: email notifications on signup --- NEW FILE: email_api.php --- <?php # Mantis - a php based bugtracking system # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details ########################################################################### # Email API ########################################################################### # -------------------- # check to see that the format is valid and that the mx record exists function is_valid_email( $p_email ) { global $g_validate_email, $g_check_mx_record; # if we don't validate then just accept if ( OFF == $g_validate_email ) { return true; } # Use a regular expression to check to see if the email is in valid format # x-xx.xxx@yyy.zzz.abc etc. if (eregi("^[_.0-9a-z-]+@([0-9a-z][-0-9a-z.]+).([a-z]{2,6}$)", $p_email, $check)) { # passed format check. see if we should check the mx records if ( ON == $g_check_mx_record ) { # Check for valid mx records if (getmxrr($check[1].".".$check[2], $temp)) { return true; } else { $host = substr( strstr( $check[0], '@' ), 1 )."."; # for no mx record... try dns check if (checkdnsrr ( $host, "ANY" )) return true; } } else { # Email format was valid but did't check for valid mx records return true; } } # Everything failed. Bad email. return false; } # -------------------- # Send password to user function email_signup( $p_username, $t_password, $p_email ) { # Email Strings $s_new_account_subject = "Your new user account"; $s_new_account_greeting = "Greetings and welcome to the WebNotes. Here is the information you need to login\n\n"; $s_new_account_url = "You can login to the site here: "; $s_new_account_username = "Username: "; $s_new_account_password = "Password: "; $s_new_account_message = "After logging into the site please change your password. Also note that your password is stored via one way encryption. The staff cannot retrieve your password. If you forget your password it will have to be reset.\n\n"; $s_new_account_do_not_reply = "Do not reply to this message.\n"; # Build Welcome Message $t_message = $s_new_account_greeting. $s_new_account_username.$p_username."\n". $s_new_account_password.$t_password."\n\n". $s_new_account_message. $s_new_account_do_not_reply; $t_headers = ""; email_send( $p_email, $s_new_account_subject, $t_message, $t_headers ); } # -------------------- # Send new password when user forgets function email_reset( $p_user_id, $p_password ) { global $g_mantis_user_table, $g_path, $s_reset_request_msg, $s_account_name_msg, $s_news_password_msg; $query = "SELECT username, email FROM $g_mantis_user_table WHERE id='$p_user_id'"; $result = db_query( $query ); $row = db_fetch_array( $result ); extract( $row, EXTR_PREFIX_ALL, "v" ); # Build Welcome Message $t_message = $s_reset_request_msg."\n\n". $s_account_name_msg.": ".$v_username."\n". $s_news_password_msg.": ".$p_password."\n\n". $g_path."\n\n"; email_send( $v_email, "New Password", $t_message ); } # -------------------- # this function sends the actual email function email_send( $p_recipient, $p_subject, $p_message, $p_header="" ) { global $g_from_email, $g_enable_email_notification, $g_return_path_email, $g_use_x_priority, $g_use_phpMailer, $g_phpMailer_method, $g_smtp_host; # short-circuit if no emails should be sent if ( OFF ==$g_enable_email_notification ) { return; } $t_recipient = trim( $p_recipient ); $t_subject = trim( $p_subject ); $t_message = trim( $p_message ); # for debugging only #echo $t_recipient."<br />".$t_subject."<br />".$t_message."<br />".$t_headers; #exit; #echo "<br />xxxRecipient =".$t_recipient."<br />"; #echo "Headers =".nl2br($t_headers)."<br />"; #echo $t_subject."<br />"; #echo nl2br($t_message)."<br />"; #exit; if ( ON == $g_use_phpMailer ) { # Visit http://phpmailer.sourceforge.net # if you have problems with phpMailer include("class.phpmailer.php"); $mail = new phpmailer; # Select the method to send mail switch ( $g_phpMailer_method ) { case 0: $mail->IsMail(); break; case 1: $mail->IsSendmail(); break; case 2: $mail->IsSMTP(); break; } $mail->IsHTML(false); # set email format to plain text $mail->WordWrap = 80; # set word wrap to 50 characters $mail->Priority = 0; # Urgent = 1, Not Urgent = 5, Disable = 0 $mail->Host = $g_smtp_host; $mail->From = $g_from_email; $mail->FromName = ""; # add to the Recipient list $t_recipient_list = split(",", $t_recipient); while ( list( , $t_recipient ) = each( $t_recipient_list ) ) { if ( !empty( $t_recipient ) ) { $mail->AddAddress( $t_recipient, "" ); } } # add to the BCC list $t_bcc_list = split(",", $p_header); while(list(, $t_bcc) = each($t_bcc_list)) { if ( !empty( $t_bcc ) ) { $mail->AddBCC($t_bcc, ""); } } $mail->Subject = $t_subject; $mail->Body = make_lf_crlf( "\n".$t_message ); if( !$mail->Send() ) { PRINT "PROBLEMS SENDING MAIL TO: $t_recipient<br />"; PRINT "Mailer Error: ".$mail->ErrorInfo."<br />"; exit; } } else { # Visit http://www.php.net/manual/function.mail.php # if you have problems with mailing $t_headers = "From: $g_from_email\n"; #$t_headers .= "Reply-To: $p_reply_to_email\n"; $t_headers .= "X-Sender: <$g_from_email>\n"; $t_headers .= "X-Mailer: PHP/".phpversion()."\n"; if ( ON == $g_use_x_priority ) { $t_headers .= "X-Priority: 0\n"; # Urgent = 1, Not Urgent = 5, Disable = 0 } $t_headers .= "Return-Path: <$g_return_path_email>\n"; # return email if error # If you want to send foreign charsets # $t_headers .= "Content-Type: text/html; charset=iso-8859-1\n"; $t_headers .= $p_header; $t_recipient = make_lf_crlf( $t_recipient ); $t_subject = make_lf_crlf( $t_subject ); $t_message = make_lf_crlf( $t_message ); $t_headers = make_lf_crlf( $t_headers ); $result = mail( $t_recipient, $t_subject, $t_message, $t_headers ); if ( TRUE != $result ) { PRINT "PROBLEMS SENDING MAIL TO: $t_recipient<p>"; PRINT htmlspecialchars($t_recipient)."<br />"; PRINT htmlspecialchars($t_subject)."<p>"; PRINT nl2br(htmlspecialchars($t_headers))."<br />"; #PRINT nl2br(htmlspecialchars($t_message))."<p>"; exit; } } } # -------------------- # helper function function get_bug_summary( $p_bug_id ) { global $g_mantis_bug_table; $query = "SELECT summary FROM $g_mantis_bug_table WHERE id='$p_bug_id'"; $result = db_query( $query ); return db_result( $result, 0, 0 ); } # -------------------- # -------------------- # clean up LF to CRLF function make_lf_crlf( $p_string ) { global $g_mail_send_crlf; if ( ON == $g_mail_send_crlf ) { $p_string = str_replace( "\n", "\r\n", $p_string ); return str_replace( "\r\r\n", "\r\n", $p_string ); } else { return $p_string; } } # -------------------- ?> Index: api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/api.php,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- api.php 16 Sep 2002 13:27:20 -0000 1.22 +++ api.php 17 Sep 2002 00:55:35 -0000 1.23 @@ -66,6 +66,7 @@ require_once( $t_path_core . 'link_api.php' ); require_once( $t_path_core . 'util_api.php' ); require_once( $t_path_core . 'gpc_api.php' ); + require_once( $t_path_core . 'email_api.php' ); require_once( $t_path_main . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $g_theme . DIRECTORY_SEPARATOR . 'theme_api.php' ); Index: config_inc.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/config_inc.php,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- config_inc.php 16 Sep 2002 13:27:20 -0000 1.16 +++ config_inc.php 17 Sep 2002 00:55:35 -0000 1.17 @@ -132,7 +132,87 @@ # AUTH_MD5, AUTH_CRYPT, AUTH_PLAIN $g_auth_type = AUTH_PLAIN; + + ############################# + # Mantis Email Settings + ############################# + + # --- email variables ------------- + $g_administrator_email = "administrator@nowhere"; + $g_webmaster_email = "webmaster@nowhere"; + + # the "From: " field in emails + $g_from_email = "noreply@nowhere"; + + # the "To: " address all emails are sent. This can be a mailing list or archive address. + # Actual users are emailed via the bcc: fields + $g_to_email = "nobody@nowhere"; + + # the return address for bounced mail + $g_return_path_email = "admin@nowhere"; # allow users to signup for their own accounts - $g_allow_signup = ON; + $g_allow_signup = ON; + + # if ON users will be sent their password when reset. + # if OFF the password will be set to blank. + $g_send_reset_password = ON; + + # allow email notification + $g_enable_email_notification = ON; + + # notify developers and higher when a new bug comes in + # only if their preference is also set + $g_notify_developers_on_new = ON; + + # set to OFF to disable email check + $g_validate_email = ON; + $g_check_mx_record = ON; + + # This disables the automatic generation of mailto: links + # Valid values: NONE, ALL, NO_ANONYMOUS, ADMIN_ONLY + $g_show_user_email = OFF; + + # Set to OFF to remove X-Priority header + $g_use_x_priority = ON; + + # Set to OFF on Windows systems, as long as php-mail-function has its bcc-bug (~PHP 4.0.6) + $g_use_bcc = ON; + + # some Mail transfer agents (MTAs) don't like bare linefeeds... + # or they take good input and create barelinefeeds + # If problems occur when sending mail through your server try turning this OFF + # more here: http://pobox.com/~djb/docs/smtplf.html + $g_mail_send_crlf = OFF; + + # phpMailer instead of standard mail() function (REQUIRES PHP 4.x.x) + # Get the phpMailer-package from http://phpmailer.sourceforge.net + # The installation is very simple you only need 2 plain text php-files + # class.smtp.php + # class.phpmailer.php + + # Copy these files to your php-include-dir i.e. "c:\php\includes" or + # "/usr/lib/php/includes" + # and add this path to the "include_path"-entry in the php.ini file. + # The installation is described in the readme and there is also a simple + # example. + # PhpMailer comes with a detailed documentation in phpdoc format. + + $g_use_phpMailer = OFF; + + # select the method to mail by: + # 0 - mail() + # 1 - sendmail + # 2 - SMTP + $g_phpMailer_method = 0; + + # This option allows you to use a remote SMTP host. Must use the phpMailer script + # Name of smtp host, needed for phpMailer, taken from php.ini + $g_smtp_host = "localhost"; + + # --- email separator and padding ------------ + $g_email_separator1 = "======================================================================="; + $g_email_separator2 = "-----------------------------------------------------------------------"; + $g_email_padding_length = 28; + ?> Index: user_api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/user_api.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- user_api.php 16 Sep 2002 13:27:20 -0000 1.6 +++ user_api.php 17 Sep 2002 00:55:35 -0000 1.7 @@ -49,11 +49,12 @@ } $t_password = create_random_password( $p_email ); - echo "Password is '$t_password'.<br />"; + if ( false === user_create( $p_username, $t_password, $p_email ) ) { return false; } - + + email_signup($p_username, $t_password, $p_email); # @@@@ Send e-mail here. return true; |