2016-10-10 3 views
1

html 웹 사이트의 문의 양식에이 코드를 사용하고 있지만 Gmail받은 편지함에는 메일이 들어 있지 않습니다.이 PHP 코드를 사용하여 Gmail받은 편지함에 이메일이 전송되지 않습니다.

아무도 내가이 문제를 해결하려고 노력하고 있지만 어떤 가이드가 없어도 도움이 될 수 있습니까?

<?php 
session_cache_limiter('nocache'); 
$subject = $_REQUEST['subject']; // Subject of your email 
$to = "[email protected]"; //Recipient's E-mail 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= "From: " . $_REQUEST['name'].'<'.$_REQUEST['email'] .'>'. "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

$message = 'Name: ' . $_REQUEST['name'] . "<br>"; 
$message .= 'Company: ' . $_REQUEST['company'] . "<br>"; 
$message .= $_REQUEST['message']; 

if (@mail($to, $subject, $message, $headers)) 
{ 
    // Transfer the value 'sent' to ajax function for showing success message. 
    echo 'sent'; 
    // header('Location: ../index.html'); 
} 
else 
{ 
    // Transfer the value 'failed' to ajax function for showing error message. 
    echo 'failed'; 
} 
?> 
+0

사용 메일 기능 기능은 모든 경고를 포기하지 않습니다 at.mail/오류가 당신에게 스팸 메일을 확인 – user3099298

+0

: https://github.com/PHPMailer/PHPMailerPHPMailer/PHPMailerPHPMailer

당신이 시도 할 수있는 또 다른 코드가있다. – Veer

+0

정확한 From Mail Id를 언급해야합니다. 나는 며칠 전 같은 문제에 직면했다. –

답변

0

로컬 서버에서이 프로그램을 개발할 경우. 이메일은 Gmail 계정으로 전송되지 않습니다.

로컬 컴퓨터에서 코드를 테스트하려면 Test Mail Server Tool을 설치하십시오.

로컬 컴퓨터에서 실행되는 동안 전자 메일이 배달되지 않지만 전자 메일의 모양을 알 수 있습니다.

웹 호스팅 서버에서 동일한 것을 실행하면 $to 필드에 지정된 전자 메일 아이디로 전자 메일이 배달됩니다.

1

헤더 설정시 약간의 문제가 있습니다. 가장 중요한 것은 From 섹션에 올 바르고 유효한 이메일 아이디를 정의해야한다는 것입니다. 구글이 일반적으로 도메인의 유효성 확인에 사용했기 때문입니다.

google 엔드에 흰색으로 표시되지 않으면 메일이 자동으로 스팸으로 종료됩니다.

PHP 메일 기능이 잘 구성된 SMTP 서버를 사용하지 않는 문제는 간단합니다. 요즘 전자 메일 클라이언트와 서버는 Reverse DNS 조회, Graylisting 및 whatev와 같이 서버를 보내는 전자 메일에 대한 대규모 검사를 수행합니다. 이 모든 테스트는 php mail() 함수와 함께 실패합니다. 유동 IP를 사용하고 있다면, PHPMailer-Class를 사용하고 잘 구성된 전용 SMTP 서버 (로컬 서버 또는 원격 서버)와 함께 smtp-auth를 사용하도록 구성하면 문제가

입니다

아래 코드를 시도해 볼 수 있습니다.

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "Return-Path: [email protected]\r\n"; 
$headers .= "CC: [email protected]\r\n"; 
$headers .= "BCC: [email protected]\r\n"; 

참조 링크. 대신 at.mail

function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { 
$file = $path.$filename; 
$file_size = filesize($file); 
$handle = fopen($file, "r"); 
$content = fread($handle, $file_size); 
fclose($handle); 
$content = chunk_split(base64_encode($content)); 
$uid = md5(uniqid(time())); 
$header = "From: ".$from_name." <".$from_mail.">\r\n"; 
$header .= "Reply-To: ".$replyto."\r\n"; 
$header .= "MIME-Version: 1.0\r\n"; 
$header .= "Content-Type: multipart/mixed;boundary=\"".$uid."\"\r\n\r\n"; 
$header .= "This is a multi-part message in MIME format.\r\n"; 
$header .= "--".$uid."\r\n"; 
$header .= "Content-type:text/plain;charset=iso-8859-1\r\n"; 
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
$header .= $message."\r\n\r\n"; 
$header .= "--".$uid."\r\n"; 
$header .= "Content-Type: application/octet-stream;name=\"".$filename."\"\r\n"; 
// use different content types here$header .= "Content-Transfer-Encoding: base64\r\n"; 
$header .= "Content-Disposition: attachment;filename=\"".$filename."\"\r\n\r\n"; 
$header .= $content."\r\n\r\n"; 
$header .= "--".$uid."--"; 
if (mail($mailto, $subject, "", $header)) {echo "mail send ... OK"; 
    // or use booleans here} else {echo "mail send ... ERROR!"; 
} 
} 
+0

올바른 보낸 사람 ID를 언급해야합니다. –

관련 문제