2012-03-30 3 views
0

я получаю две ошибки при попытке отправить почту:Проблемы с отправкой почты через PHPMailer

Warning: fsockopen() [function.fsockopen]: unable to connect to mail.localhost.com:25 (A 
    connection attempt failed because the connected party did not properly respond after 
    a period of time, or established connection failed because connected host has failed 
    to respond.) in C:\xampp\htdocs\euisample\class.smtp.php on line 122 

SMTP -> ERROR: Failed to connect to server: A connection attempt failed because 
the connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to respond. 
(10060) Mailer 
Error: SMTP Error: Could not connect to SMTP host. 

На данный момент я просто использовать этот тестовый скрипт

require("class.phpmailer.php"); 
$mail = new PHPMailer(); 
$message = "Hello \n 
     Thank you for registering with us. Here are your login details...\n 
     User ID: $user_name 
     Email: $usr_email \n 
     Passwd: $data[pwd] \n"; 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "mail.localhost.com"; // SMTP server 
$mail->SMTPDebug = 2; 
$mail->SMTPAuth = true; // enable SMTP authentication 
$mail->Host  = "mail.localhost.com"; // sets the SMTP server 
$mail->Port  = 25; // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // SMTP account username 
$mail->Password = "xxx"; // SMTP account password 
$mail->AddReplyTo("[email protected]", "First Last"); 
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; 
$mail->MsgHTML($message); 
$address = $usr_email; 
$mail->AddAddress($address, "John Doe"); 

мне нужна система для отправки сообщений электронной почты. Если это невозможно с localhost, будет ли он работать с Gmail? Любые другие предложения?

ответ

0

Для отправки электронных писем вам нужен настоящий SMTP-сервер. Поскольку у вас, очевидно, нет SMTP-сервера, установленного на локальном хосте, ваш единственный вариант - использовать сторонний сервер. Например, вы можете использовать GMail, и вот как это сделать.

require_once('class.phpmailer.php'); 

try { 
    $mail = new PHPMailer(true); 
    $mail->IsSMTP(); // Using SMTP. 
    $mail->CharSet = 'utf-8'; 
    $mail->SMTPDebug = 2; // Enables SMTP debug information - SHOULD NOT be active on production servers! 
    $mail->SMTPSecure = 'tls'; 
    $mail->SMTPAuth = true; // Enables SMTP authentication. 
    $mail->Host = "smtp.gmail.com"; // SMTP server host. 
    $mail->Port = 587; // Setting the SMTP port for the GMAIL server. 
    $mail->Username = "EMAIL/USERNAME"; // SMTP account username (GMail email address). 
    $mail->Password = "PASSWORD"; // SMTP account password. 
    $mail->AddReplyTo('EMAIL', 'NAME'); // Use this to avoid emails being classified as spam - SHOULD match the GMail email! 
    $mail->AddAddress('EMAIL', 'NAME'); // Recipient email/name. 
    $mail->SetFrom('EMAIL', 'NAME'); // Sender - SHOULD match the GMail email. 
    $mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication'; 
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 
    $mail->MsgHTML($message); 
    $mail->Send(); 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
} catch (Exception $e) { 
    echo $e->getMessage(); //Boring error messages from anything else! 
} 
+0

Я сейчас получаю эти ошибки 'Warning: fsockopen() [function.fsockopen]: не удалось подключиться к ДУС: //smtp.gmail.com: 587 (Не удалось найти сокет транспорта "TLS" - вы забыли включить его при настройке PHP?) в C: \ xampp \ htdocs \ euisample \ class.smtp.php в строке 122 SMTP -> ОШИБКА: Не удалось подключиться к серверу: невозможно найти перенос сокетов " tls "- вы забыли включить его при настройке PHP? ' – user1296762

+0

Вам нужно mod_ssl включить в XAMPP, чтобы использовать TLS. – brezanac

+0

Как это сделать? В файле httpd-ssl? – user1296762

Смежные вопросы