求助

gaosanlioushui 2010-10-21 07:06:06
我希望把mantis发送的邮件的路径(http://10.67.1.1:8008/view.php?id=21 ) 改称
指定的域名路径(http://mantis_test:8008/view.php?id=21 ) 有人知道如何改写吗?我对php 不懂。
下面是个mantis 的email_api.php 我把发送EMail的方法抽取出来了,希望大家帮我看看。
<?php
# Send password to user
function email_signup( $p_user_id, $p_password, $p_confirm_hash )
{
if ( ( OFF == config_get( 'send_reset_password' ) ) || ( OFF == config_get( 'enable_email_notification' ) ) ) {return;}
$t_username = user_get_field( $p_user_id, 'username' );
$t_email = user_get_email( $p_user_id );
# Build Welcome Message
$t_subject = '[' . config_get( 'window_title' ) . '] ' . lang_get( 'new_account_subject' );
$t_message = lang_get( 'new_account_greeting' ) . $t_username .
lang_get( 'new_account_greeting2' ) . " \n\n" .
string_get_confirm_hash_url( $p_user_id, $p_confirm_hash ) . " \n\n" .
lang_get( 'new_account_message' ) .
lang_get( 'new_account_do_not_reply' );
# Send signup email regardless of mail notification pref
# or else users won't be able to sign up
if( !is_blank( $t_email ) ) {
email_store( $t_email, $t_subject, $t_message );
log_event( LOG_EMAIL, "signup=$t_email, hash=$p_confirm_hash, id=$p_user_id" );

if ( OFF == config_get( 'email_send_using_cronjob' ) ) {
email_send_all();
}
}
}
# Send confirm_hash url to user forgets the password
function email_send_confirm_hash_url( $p_user_id, $p_confirm_hash ) {
if ( ( OFF == config_get( 'send_reset_password' ) ) || ( OFF == config_get( 'enable_email_notification' ) ) ) {
return;
}
lang_push( user_pref_get_language( $p_user_id ) );
# retrieve the username and email
$t_username = user_get_field( $p_user_id, 'username' );
$t_email = user_get_email( $p_user_id );
$t_subject = '[' . config_get( 'window_title' ) . '] ' . lang_get( 'lost_password_subject' );

$t_message = lang_get( 'reset_request_msg' ) . " \n\n" .
string_get_confirm_hash_url( $p_user_id, $p_confirm_hash ) . " \n\n" .
lang_get( 'new_account_username' ) . $t_username . " \n" .
lang_get( 'new_account_IP' ) . $_SERVER["REMOTE_ADDR"] . " \n\n" .
lang_get( 'new_account_do_not_reply' );
# Send password reset regardless of mail notification prefs
# or else users won't be able to receive their reset pws
if( !is_blank( $t_email ) ) {
email_store( $t_email, $t_subject, $t_message );
log_event( LOG_EMAIL, "password_reset=$t_email" );

if ( OFF == config_get( 'email_send_using_cronjob' ) ) {
email_send_all();
}
}
lang_pop();
}
# --------------------
# send a generic email
# $p_notify_type: use check who she get notified of such event.
# $p_message_id: message id to be translated and included at the top of the email message.
# Return false if it were problems sending email
function email_generic( $p_bug_id, $p_notify_type, $p_message_id = null, $p_header_optional_params = null ) {
$t_ok = true;
if ( ON === config_get( 'enable_email_notification' ) ) {
ignore_user_abort( true );
# @@@ yarick123: email_collect_recipients(...) will be completely rewritten to provide additional
# information such as language, user access,..
# @@@ yarick123:sort recipients list by language to reduce switches between different languages
$t_recipients = email_collect_recipients( $p_bug_id, $p_notify_type );

$t_project_id = bug_get_field( $p_bug_id, 'project_id' );
if ( is_array( $t_recipients ) ) {
log_event( LOG_EMAIL, sprintf("bug=%d, type=%s, msg=%s, recipients=(%s)", $p_bug_id, $p_notify_type, $p_message_id, implode( '. ', $t_recipients ) ) );
# send email to every recipient
foreach ( $t_recipients as $t_user_id => $t_user_email ) {
# load (push) user language here as build_visible_bug_data assumes current language
lang_push( user_pref_get_language( $t_user_id, $t_project_id ) );

$t_visible_bug_data = email_build_visible_bug_data( $t_user_id, $p_bug_id, $p_message_id );
$t_ok = email_bug_info_to_one_user( $t_visible_bug_data, $p_message_id, $t_project_id, $t_user_id, $p_header_optional_params ) && $t_ok;
lang_pop();
}
}
# Only trigger the draining of the email queue if cronjob is disabled and email notifications are enabled.
if ( OFF == config_get( 'email_send_using_cronjob' ) ) {
email_send_all();
}
}
return $t_ok;
}
# --------------------
function email_store( $p_recipient, $p_subject, $p_message, $p_headers = null ) {
$t_recipient = trim( $p_recipient );
$t_subject = string_email( trim( $p_subject ) );
$t_message = string_email_links( trim( $p_message ) );
# short-circuit if no recipient is defined, or email disabled
# note that this may cause signup messages not to be sent

if ( is_blank( $p_recipient ) || ( OFF == config_get( 'enable_email_notification' ) ) ) {
return;
}
$t_email_data = new EmailData;
$t_email_data->email = $t_recipient;
$t_email_data->subject = $t_subject;
$t_email_data->body = $t_message;
$t_email_data->metadata = array();
$t_email_data->metadata['headers'] = $p_headers === null ? array() : $p_headers;
$t_email_data->metadata['priority'] = config_get( 'mail_priority' ); # Urgent = 1, Not Urgent = 5, Disable = 0
$t_email_data->metadata['charset'] = lang_get( 'charset', lang_get_current() );
$t_hostname = '';
$t_server = isset( $_SERVER ) ? $_SERVER : $HTTP_SERVER_VARS;
if ( isset( $t_server['SERVER_NAME'] ) ) {
$t_hostname = $t_server['SERVER_NAME'];
} else {
$t_address = explode( '@', config_get( 'from_email' ) );
if ( isset( $t_address[1] ) ) {
$t_hostname = $t_address[1];
}
}
$t_email_data->metadata['hostname'] = $t_hostname;
$t_email_id = email_queue_add( $t_email_data );
return $t_email_id;
}
# --------------------
# This function sends an email message based on the supplied email data.
function email_send( $p_email_data ) {
global $g_phpMailer_smtp;
$t_email_data = $p_email_data;
$t_recipient = trim( $t_email_data->email );
$t_subject = string_email( trim( $t_email_data->subject ) );
$t_message = string_email_links( trim( $t_email_data->body ) );
$t_debug_email = config_get( 'debug_email' );
# Visit http://phpmailer.sourceforge.net
# if you have problems with phpMailer
$mail = new PHPMailer;
$mail->PluginDir = PHPMAILER_PATH;

if ( isset( $t_email_data->metadata['hostname'] ) ) {
$mail->Hostname = $t_email_data->metadata['hostname'];}
$t_lang = config_get( 'default_language' );
if ( 'auto' == $t_lang ) {
$t_lang = config_get( 'fallback_language');}
$mail->SetLanguage( lang_get( 'phpmailer_language', $t_lang ), PHPMAILER_PATH . 'language' . DIRECTORY_SEPARATOR );
# Select the method to send mail
switch ( config_get( 'phpMailer_method' ) ) {
case 0: $mail->IsMail();
break;
case 1: $mail->IsSendmail();
break;
case 2: $mail->IsSMTP();
{$mail->SMTPKeepAlive = true;
if( is_null( $g_phpMailer_smtp ) ) {
register_shutdown_function( 'email_smtp_close' );
} else {$mail->smtp = $g_phpMailer_smtp;}
}
break;
}
$mail->IsHTML( false ); # set email format to plain text
$mail->WordWrap = 80; # set word wrap to 50 characters
$mail->Priority = $t_email_data->metadata['priority']; # Urgent = 1, Not Urgent = 5, Disable = 0
$mail->CharSet = $t_email_data->metadata['charset'];
$mail->Host = config_get( 'smtp_host' );
$mail->From = config_get( 'from_email' );
$mail->Sender = escapeshellcmd( config_get( 'return_path_email' ) );
$mail->FromName = config_get( 'from_name');
if ( !is_blank( config_get( 'smtp_username' ) ) ) { # Use SMTP Authentication
$mail->SMTPAuth = true;
$mail->Username = config_get( 'smtp_username' );
$mail->Password = config_get( 'smtp_password' );
}
if ( OFF !== $t_debug_email ) {
$t_message = 'To: '. $t_recipient . "\n\n" . $t_message;
$mail->AddAddress( $t_debug_email, '' );
} else {
$mail->AddAddress( $t_recipient, '' );
}
$mail->Subject = $t_subject;
$mail->Body = make_lf_crlf( "\n" . $t_message );
if ( isset( $t_email_data->metadata['headers'] ) && is_array( $t_email_data->metadata['headers'] ) ) {
foreach ( $t_email_data->metadata['headers'] as $t_key => $t_value ) {
$mail->AddCustomHeader( "$t_key: $t_value" );
}
}
if ( !$mail->Send() ) {
$t_success = false;
} else {
$t_success = true;
if ( $t_email_data->email_id > 0 ) {
email_queue_delete( $t_email_data->email_id );
}
}
if ( !is_null( $mail->smtp ) ) {
$g_phpMailer_smtp = $mail->smtp;
}
return $t_success;
}
?>
...全文
94 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
在-云端 2010-11-01
看的蛋疼!!太长~~
回复
shao_jingna 2010-11-01
看了就晕,我帮不了你了,顶一下吧
回复
zhangyanhe162 2010-10-22
期待中。。。
回复
相关推荐
发帖
PHP
创建于2008-08-27

1.9w+

社区成员

“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
申请成为版主
帖子事件
创建了帖子
2010-10-21 07:06
社区公告
暂无公告