2016-05-31 1 views
0

EDIT : 코드는 웹 서버에서만 작동하며 localhost에서는 작동하지 않습니다. 따라서 "수정 사항"이 있습니다. = 1)PHPMailer는 한 페이지에서 작동하지만 비슷하게 작동하지 않습니다

require 'PHPMailer/PHPMailerAutoload.php'; 
    $nome = $_POST["nome"]; 
    $subject = $_POST["subject"]; 
    $message = $_POST["message"]; 
    $email = $_POST["email"]; 
    $contacto = $_POST["contacto"]; 
    $body = "<p>Mail recebido de: </p>" . $nome . "<p>Email:</p>" . $email . "<p> Contacto:</p>" . $contacto . "<p>Mensagem:</p>" . $message ; 
    $mail = new PHPMailer(); 
    $mail->CharSet = "text/html; charset=UTF-8;"; 
    $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only 
    $mail->CharSet = 'UTF-8'; 
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = 'ssl'; 
    $mail->Host = "smtp.gmail.com"; 
    $mail->Port = 587; 
    $mail->Username = "the email"; 
    $mail->Password = the password; 
    $mail->SetFrom('the email', 'Organizer'); 
    $mail->Subject = "[ORÇAMENTO] " . $subject; 
    $mail->Body = $body; 
    $mail->IsHTML(true); 
    $mail->AddAddress("the email"); 
    if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    $sucesso = 'Mensagem enviada com sucesso!'; 
} 

이 첫 번째 스크립트가 자신에게 이메일을 보내지 만, 심지어는 (보내기> 여기 ($ 메일 - 작동하지 않습니다

그래서, 내 PHP 코드는이를 좋아한다으로 작동 여전히 나는) 이메일을 수신하지 않습니다 : 나는 등 데이터베이스에서 얻을 모든 변수를 테스트 한 그들은 모두 올바른

require '../PHPMailer/PHPMailerAutoload.php'; 
      $body = "<p>Car(a) " . ${'user' . $i} . ",</p> <p> Foi lhe associado(a) uma nova ocorrência. Consulte-a em http://www.organizer.com.pt . </p>"; 
      $mail = new PHPMailer(); 
      $mail->CharSet = "text/html; charset=UTF-8;"; 
      $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
      $mail->CharSet = 'UTF-8'; 
      $mail->SMTPAuth = true; 
      $mail->SMTPSecure = 'ssl'; 
      $mail->Host = "smtp.gmail.com"; 
      $mail->Port = 587; 
      $mail->Username = "the email"; 
      $mail->Password = the password; 
      $mail->SetFrom('the email', 'Organizer'); 
      $mail->Subject = "Nova Ocorrência"; 
      $mail->Body = $body; 
      $mail->IsHTML(true); 
      $mail->AddAddress($email); 
      if(!$mail->Send()) { 
      echo "Mailer Error: " . $mail->ErrorInfo; 
      } else { 
      $sucesso = 'Mensagem enviada com sucesso!'; 
      } 

, 난 그냥 어떤 이유로 이메일을 수신하지 않습니다 . 누구든지 도울 수 있니?

피씨 : 죄송합니다 일부는 포르투갈어로되어 있습니다. 코드는 여전히 완벽하게 이해할 수 있습니다.

+0

오류 메시지가 있습니까? –

+0

아니, 아마 메일이 전송됩니다, 그 이유는 이해가 안 돼요. – Manuel

+0

체크인 스크립트 2 ... "필요합니다 .. ../PHPMailer/PHPMailerAutoload.php ';" 또는 " 'PHPMailer/PHPMailerAutoload.php';" –

답변

0

"작동하지 않음"은 유용한 문제 설명이 아닙니다. 그럼, 세부 사항이 전부입니다.

잘못된 코드 예 : & 잘못된 예를 기반으로하고 문서를 읽지 않았거나 PHPMailer의 이전 버전을 사용하고있는 것으로 의심됩니다. 링크를 제공 했으므로 관련 문서가 최신 버전 인 경우 그래서 무엇보다도 먼저 get the latest versionread the docs.

특정 문제 : SMTPSecure = 'ssl'Port = 587은 작동하지 않습니다. 포트 587은 암시 적 SSL이 아닌 SMTP + STARTTLS에 사용되므로 SMTPSecure = 'tls'으로 설정하십시오.

이것은 단지 잘못 :

$mail->CharSet = "text/html; charset=UTF-8;"; 

귀하의 다른 스크립트를 마우스 오른쪽 수행합니다

$mail->CharSet = 'UTF-8'; 

당신이 디버깅 옵션이 뭔가 문제가있는 경우 활성화!

$mail->SMTPDebug = 2; 

초기 연결 문제가있는 경우 3으로 늘립니다.

필자에게 예제 코드를 어디에서 얻었는지 알고 싶습니다. 작성자에게 삭제 또는 업데이트하도록 요청할 수 있습니다. 깨진, 쓸데없는 예를 들어 주위에 거짓말 그냥 모두 낭비.

관련 문제