2013-10-10 18 views
6

PHP için tamamen yeni ve PHP kullanarak posta göndermek istiyorum. Bana ulaşan kişinin e-posta adresini kabul edecek bir İletişim Formu aldım ve bu yüzden posta bana gönderilecek. PHPMailer kitaplığı https://github.com/PHPMailer/PHPMailer/tree/master'dan kullanıyorum ve aşağıdaki kod snippet'i kullanıyorum.SMTP connect() PHPMailer'de hata oldu

<?php 
require("class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); 

$mail->SMTPSecure = 'tls'; 

$mail->Host  = "resolver1.opendns.com"; // this SMTP server of my machine 
//$mail->Host  = "208.67.222.222";//ip ; which one to use the resolver1.opendns.com or 208.67.222.222 ??? 

$mail->From  = "[email protected];//email id of the person 

$mail->AddAddress("[email protected]");//my email id 

$mail->Subject = "First PHPMailer Message"; 
$mail->Body  = "Hi! \n\n This is my first e-mail sent through PHPMailer."; 
$mail->WordWrap = 50; 

if(!$mail->Send()) 
{ 
    echo 'Message was not sent.'; 
    echo 'Mailer error: ' . $mail->ErrorInfo; 
} 
else 
{ 
    echo 'Message has been sent.'; 
} 
?> 

"İleti gönderilmedi.Mailer hatası: SMTP connect() başarısız oldu." Problemin ne olduğunu anlamıyorum ..? $ mail-> Host = ""; Lütfen bunun ne anlama geldiğini yorumlayınız?

+0

sonra lütfen kaldırın ağ arayüzü bir IPv6 adresi varsa. –

+0

Bu resolver1.opendns.com'un e-postanızı kabul edeceğini sanmıyorum. –

+0

Çalışması için '$ mail-> Port = $ SmtpPort;' eklemek zorunda kaldım. Geliştirme sunucusunda çalıştı, ancak bundan önceki üretimde değil. – minipif

cevap

0

Sen resolver1.opendns.com ait tcp portunu 25 kontrol etmelidir, böyle sendmail ya da bazı MTA olarak stmpd başlatırken blok olup olmaması seens.

telnet resolver1.opendns.com deneyin ve TCP portu 25 açılmaz bulacaksınız.

23

$mail->SMTPDebug = 1; ekleyin ve sorunu hata ayıklamak için deneyin.

+0

Benim için, RHEL sistemimde Postfix'i yapılandırdığımda bu hatayı aldım ancak henüz alternatifleri kullanarak varsayılan MTA'ya geçirmemiştim. – im3r3k

1

Belki de yapılandırma sorununuz budur. phpmailer yapılandırmanın

örnek şu şekildedir:

<?php 
require 'class.phpmailer.php'; 

$mail = new PHPMailer; 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'jswan';       // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 

$mail->From = '[email protected]'; 
$mail->FromName = 'Mailer'; 
$mail->addAddress('[email protected]', 'Josh Adams'); // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->WordWrap = 50;         // Set word wrap to 50 characters 
$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
    exit; 
} 

echo 'Message has been sent'; 

işte $ posta-> Ana Bilgisayar smtp posta sunucusudur. Normalde smtp ile başladı.

4

olarak çok iyi SMTP üzerinden bağlanmak için, @joydesigner tarafından exampled, sen hostname, username and password geçmesi gerekecektir ve daha sonra bağlanmak ve e-posta göndermesi gerekmektedir. İşte

$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'jswan';       // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // tls or ssl connection as req 

Ben sadece, host bilgi pls yanı username & password eklemek ve bir kez deneyin geçti görüyoruz.

Ayrıca TLS/SSL PORT Sunucunuz için açık olup olmadığını kontrol edin:

onay ile:

telnet resolver1.opendns.com 25