사람들이 정보를 제출하면 첨부 파일이있는 이메일을 보내는 PHP 스크립트가 있습니다. 나는이 메일을 Gmail의받은 편지함에 문제없이 수신합니다. 그러나 개인 이메일 주소 나 직장 이메일 주소를 사용하면 이메일이 배달되지 않습니다. 이 문제는 내 스크립트 (아래) 또는 서버의 일부 설정에 문제가 있습니까? 나는 그것이 헤더에 문제가있을 수 있다고 생각하지만, 헤더를 변경할 때마다 전자 메일을 중단하고 모든 것이 메시지 본문에 표시됩니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까? 서버는 plesk 제어판이있는 클라이언트 관리 형 Linux 서버이므로 PHP ini 파일에 액세스 할 수 없습니다.php mail() 이메일은 Gmail 계정에 있지만 일반 이메일 계정에는 도착하지 않습니다.
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Email with Attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$mime_boundary = "<<<--==+X[".md5(time())."]";
$path = $_SERVER['DOCUMENT_ROOT'].'/two/php/';
$fileContent = chunk_split(base64_encode(file_get_contents($path.'CTF_brochure.pdf')));
$headers .= "From: [email protected] <[email protected]>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";
$message = "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "Email content and what not: \r\n";
$message .= "This is the file you asked for! \r\n";
$message .= "--".$mime_boundary."" . "\r\n";
$message .= "Content-Type: application/octet-stream;\r\n";
$message .= " name=\"CTF-brochure.pdf\"" . "\r\n";
$message .= "Content-Transfer-Encoding: base64 \r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= " filename=\"CTF_brochure.pdf\"\r\n";
$message .= "\r\n";
$message .= $fileContent;
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
//send the email
$mail_sent = mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
하이 드류를 저장합니다. 다른 Gmail이 아닌 계정으로 보낼 때 "Mail sent"또는 "Mail failed"가 출력되었습니다. 다른 Gmail 계정으로 보내시겠습니까? – mauris
매번 출력되는 메일은 – Drew