나는 내 질문과 유사한 질문이 많다는 것을 알고 있으며, 그 중 일부를 통해 살펴본 결과 아무도 내 질문에 대답하지 않은 것으로 나타났습니다.이메일 SQL 첨부 문제
기본적으로 자신의 데이터베이스 덤프를 생성하여 전자 메일로 보내는 클라이언트 용 스크립트를 만들었습니다. 아래 코드를 게시하면 데이터베이스 정보가 스크립트를 통해 생성되고 물리적 SQL 파일이 생성되지 않습니다. 서버에서 대신 변수에 모두 추가 한 다음 변수를 사용하여 데이터베이스 정보를 전자 메일 헤더에 첨부합니다.
또한 전자 메일 첨부 파일 코드를 사용하여 정상적으로 작동하지만 실제로는 파일이 실제로 존재하므로 문제라고 생각하기 시작했습니다.
<?php
//Script configuration section.
$D_hostname = 'localhost'; # Database hostname.
$D_username = 'username'; # Database username.
$D_password = 'password'; # Database password.
$D_database = 'database'; # Database name.
$E_from = '{BLOG BACKUP} <[email protected]>'; # From header.
$E_subject = '[' . date('d-m-Y') . ']: This weeks database backup.'; # Email subject.
$E_content = 'This weeks database backup has been created, please find it attached to this email. Remember to save a copy and retain this email too!<br />'; #Email content.
$E_filename = date('d-m-Y') . '_blog_backup.sql'; #Attachment filename.
$E_filetype = 'application/octet-stream'; # Attachment type.
$E_recipients = '[email protected], [email protected]'; #Email recipients.
//Connect to the database.
$connection = mysql_connect($D_hostname, $D_username, $D_password);
//Select the database
mysql_select_db($D_database, $connection);
//Set up an empty array.
$tables = array();
//Get a list of all the databases tables.
$Q_show_tables = mysql_query('SHOW TABLES');
//Add each table to the array.
while($R_show_tables = mysql_fetch_row($Q_show_tables)){
$tables[] = $R_show_tables[0];
}
//Get all rows for each table and create a mySQL query.
foreach($tables as $table) {
//Get all rows from the table.
$Q_get_rows = mysql_query('SELECT * FROM '.$table);
$C_get_rows = mysql_num_fields($Q_get_rows);
//Add a drop clause for the table
$data_row .= 'DROP TABLE ' . $table . ';';
//Get create table info.
$Q_create_table = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
//Add the create table clause to the query.
$data_row.= "\n\n" . $Q_create_table[1] . ";\n\n";
//Now gather all of the rows.
for ($int_01 = 0; $int_01 < $C_get_rows; $int_01++) {
while($R_get_rows = mysql_fetch_row($Q_get_rows)) {
//Add the insert clause.
$data_row .= 'INSERT INTO ' . $table . ' VALUES (';
//For each field write out a row.
for($int_02 = 0; $int_02 < $C_get_rows; $int_02++) {
$R_get_rows[$int_02] = addslashes($R_get_rows[$int_02]);
$R_get_rows[$int_02] = ereg_replace("\n","\\n",$R_get_rows[$int_02]);
if (isset($R_get_rows[$int_02])) {
$data_row .= '"'.$R_get_rows[$int_02].'"' ;
} else {
$data_row .= '""';
}
if ($int_02 < ($num_fields-1)) {
$data_row .= ',';
}
}
$data_row .= ");\n";
}
}
$data_row .="\n\n\n";
}
//Split and encode the data.
$data_split = chunk_split(base64_encode($data_row));
//Create a unique boundary
$new_boundary = md5(time());
//This is your basic header information such as who the email is from and the date it was sent.
$mail_header .= 'From: ' . $E_from . "\r\n";
$mail_header .= 'Date: ' . date('r') . "\r\n";
//This part of the header first defines to the email client that it is a multipart message and adds the emails content/body.
$mail_header .= 'Content-Type: multipart/mixed; boundary="' . $new_boundary . '"' . "\r\n\r\n";
$mail_header .= 'MIME-Version: 1.0' . "\r\n";
$mail_header .= 'This is a multi-part message in MIME format' . "\r\n";
$mail_header .= '--' . $new_boundary . "\r\n";
$mail_header .= 'Content-Type:text/html; charset="iso-8859-1"' . "\r\n";
$mail_header .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";
$mail_header .= $E_content . "\r\n\r\n";
//This part of the header is for the attachment and includes the contents of the file, the files name and other information.
$mail_header .= '--' . $new_boundary . "\r\n";
$mail_header .= 'Content-Type: ' . $E_filetype . '; name="' . $E_filename . '"' . "\r\n";
$mail_header .= 'Content-Transfer-Encoding: base64' . "\r\n";
$mail_header .= 'Content-Disposition: attachment; filename="' . $E_filename . '"' . "\r\n\r\n";
$mail_header .= $data_split . "\r\n\r\n";
//This is needed to stop any rendering errors by email clients and signifies the end of the emails header.
$mail_header .= '--' . $new_boundary . '--' . "\r\n";
//This mails out all of the above.
mail($E_recipients, $E_subject, '', $mail_header);
?>
문제
: 이메일이 무리 메일 클라이언트 나 핫메일에 전혀 표시되지 않는 첨부 파일 및 메시지 내용을 전송, 아직 Gmail에서 잘 작동. 메일 헤더에 문제가있는 것 같지만 오류는 볼 수 없습니다.이메일 헤더에 문제가있는 사람은 누구입니까? 그렇다면 문제를 해결하는 방법에 대해 조언 해 줄 수 있습니까?
항상 도움을 주시면 대단히 감사하겠습니다.
나는 Gmail에서 정상적으로 표시되지만 Hotmail이나 Horde에서는 표시되지 않음을 유의해야합니다.다른 메일 클라이언트를 시도하지 않았습니다. – RobFos
사이드 노트로, 전자 메일은 가장 안전한 커뮤니케이션 수단이 아닙니다. DB를 보내면 위험합니다. –
해결책은 아니지만 코드를 살펴볼 때 [ ezMail] (http://ezcomponents.org/docs/tutorials/Mail)에서 PHP를 통해 메일을 쉽고 빠르게 보내는 모든 문제를 처리 할 수 있습니다. 바퀴를 재발 명할 필요가 없습니다. –