2017-02-15 3 views
2

여기 내 파일, 접촉 form.php (코드)SMTP 오류 : SMTP 호스트에 연결할 수 없습니다. SMTP 호스트에 연결할 수 없습니다 : Phpmailer 오류

<?php 
if(isset($_POST['submit'])) 
{ 

$message= 
'Full Name: '.$_POST['fullname'].'<br /> 
Subject: '.$_POST['subject'].'<br /> 
Phone: '.$_POST['phone'].'<br /> 
Email: '.$_POST['emailid'].'<br /> 
Comments: '.$_POST['comments'].' 
'; 
    require "phpmailer/class.phpmailer.php"; //include phpmailer class 

    // Instantiate Class 
    $mail = new PHPMailer(); 

    // Set up SMTP 
    $mail->IsSMTP();    // Sets up a SMTP connection 
    $mail->SMTPAuth = true;   // Connection with the SMTP does require authorization  
    $mail->SMTPSecure = "ssl";  // Connect using a TLS connection 
    $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address 
    $mail->Port = 465; //Gmail SMTP port 
    $mail->Encoding = '7bit'; 

    // Authentication 
    $mail->Username = "[email protected]"; // Your full Gmail address 
    $mail->Password = "yourpassword"; // Your Gmail password 

    // Compose 
    $mail->SetFrom($_POST['emailid'], $_POST['fullname']); 
    $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']); 
    $mail->Subject = "New Contact Form Enquiry";  // Subject (which isn't required) 
    $mail->MsgHTML($message); 

    // Send To 
    $mail->AddAddress("[email protected]", "Recipient Name"); // Where to send it - Recipient 
    $result = $mail->Send();  // Send! 
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';  
    unset($mail); 

} 
?> 
<html> 
<head> 
    <title>Contact Form</title> 
</head> 
<body> 

     <div style="margin: 100px auto 0;width: 300px;"> 
      <h3>Contact Form</h3> 
      <form name="form1" id="form1" action="" method="post"> 
        <fieldset> 
         <input type="text" name="fullname" placeholder="Full Name" /> 
         <br /> 
         <input type="text" name="subject" placeholder="Subject" /> 
         <br /> 
         <input type="text" name="phone" placeholder="Phone" /> 
         <br /> 
         <input type="text" name="emailid" placeholder="Email" /> 
         <br /> 
         <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> 
         <br /> 
         <input type="submit" name="submit" value="Send" /> 
        </fieldset> 
      </form> 
      <p><?php if(!empty($message)) echo $message; ?></p> 
     </div> 

</body> 
</html> 

그것은이 오류, SMTP 오류를 표시합니다.

나는 몇 시간이 질문을 여기에서 묻는다. 그러나 아무것도 나를 위해 일하지 않는다는 것을 안다, 나는 모든 이전 트릭을 여기에서 시도했다, 누군가 나를 거기에서 도와 줄 수 있었다. 정확한 위치를 오류 n은 내 코딩 ...

+0

에 대한 TLS 및 포트 587를 사용하세요? – AkiEru

+0

당신은 모든 질문을 읽고 여전히 PHPMailer의 오래된 버전과 취약한 버전을 실행하고 있으며, 더 이상 사용되지 않는 예제에 코드를 기반으로하고이 주제에 관한 모든 질문과 연결된 문서를 읽지 않았습니다. 인상 지우지 않았다. – Synchro

답변

1

아래의 사항을 읽고이

포트 25, 465, 또는 587 SSL/TLS는 선택 사항에 따라 implemet입니다. 정적 IP 주소가 하나 이상 필요합니다. 동적 IP를이

포트를 허용

포트 465 (SSL 필요) 포트 587 (TLS 필요) 25 TLS는 동적 IP를이 메일은 Gmail 또는 G 스위트 룸 사용자에게 보낼 수 있습니다 허용 필요하지

ref : - here

이 줄을 코드에 붙여 넣기 만하면 정확한 오류를 확인할 수 있습니다. SMTP 오류가 다시 발생하면 위와 같이하십시오.

참조 : - here

1

타사 SMTP 호스트를 연결 차단 호스팅 포트 587 또는 웹과 TLS를 시도 Gmail을

Set up SMTP 
$mail->IsSMTP();    // Sets up a SMTP connection 
$mail->SMTPAuth = true;   // Connection with the SMTP does require authorization  
$mail->SMTPSecure = "tls";  // Connect using a TLS connection 
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address 
$mail->Port = 587; //Gmail SMTP port 
$mail->Encoding = '7bit'; 
관련 문제