简体   繁体   English

phpmailer给SMTP错误

[英]Phpmailer giving SMTP ERROR

I have this error message. 我有此错误信息。 Could you please help me ? 请你帮助我好吗 ?

My email.php; 我的email.php;

<?php

header('Content-Type: text/html; charset=utf-8');
require 'PHPMailerAutoload.php';
$phpmailer = new PHPMailer;
$phpmailer->isSMTP();
$phpmailer->Host = 'mail.coffeewritingcontent.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'iletisim@coffeewritingcontent.com';
$phpmailer->Password = 'mypassword';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Port = '587';
$phpmailer->From = 'iletisim@coffeewritingcontent.com';
$phpmailer->FromName = $_POST['name'];
$phpmailer->AddReplyTo($_POST['email'], $_POST['name']);
$phpmailer->addAddress('iletisim@coffeewritingcontent.com', 'İletişim Formu');
$phpmailer->isHTML(true);
$phpmailer->Subject = 'İletisim formu mesajı';
$phpmailer->Body    = "isim: " . $_POST['name'] . "\r\n\r\nMesaj: " . stripslashes($_POST['message']);
$phpmailer->CharSet = 'UTF-8';
$phpmailer->SMTPDebug = 4;
if(!$phpmailer->send()) {
   echo 'Mail gonderilemedi. Hata: ' . $phpmailer->ErrorInfo;
   exit;
}

echo 'Mail gonderildi.';

?>

my error; 我的错误;

2016-03-26 21:52:59 Connection: opening to mail.coffeewritingcontent.com:587, timeout=10, options=array ( ) 2016-03-26 21:53:09 SMTP ERROR: Failed to connect to server: Connection timed out (110) Mail gonderilemedi. 2016-03-26 21:52:59连接:打开mail.coffeewritingcontent.com:587,超时= 10,options = array()2016-03-26 21:53:09 SMTP错误:无法连接到服务器:连接超时(110)邮件gonderilemedi。 Error: Language string failed to load: connect_host 错误:语言字符串无法加载:connect_host

Plase try this code. 请尝试此代码。 I'm using now in a server with GoDaddy and everything going good. 我现在在带有GoDaddy的服务器上使用,一切正常。 Please make sure to require the php library with a require_once instance 请确保要求使用带有require_once实例的php库

            $mail = new PHPMailer;
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = 'localhost';  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = 'mymail@mydomain.com';                 // SMTP username
            $mail->Password = 'password';                           // SMTP password
            $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 25;                                    // TCP port to connect to
            $mail->setFrom('mymail@mydomain.com', 'Name');
            $mail->addAddress($email); 
            $mail->isHTML(true); 

            $mail->setLanguage('es');
            $mail->CharSet = 'UTF-8';   

            $mail->Subject = 'Welcome!';

            $mail->Body  = 'This is a messagge test!';
            if ( !$mail->send() ) :
                echo 'Error while sending mail.';
             else :
                echo 'The messagge send correctly';
            endif;

Did you create an instant of $phpmailer before do all those code? 是否在所有这些代码之前创建了$ phpmailer实例 Probably you have to do it. 可能您必须这样做。 So, if you already do that, please review your file PHPMailerAutoload.php and make sure that you have into your folder all and complety files that phpmailer provide us after the download content. 因此,如果您已经这样做了,请检查您的文件PHPMailerAutoload.php,并确保将下载内容后phpmailer为我们提供的所有文件和完整文件都放入文件夹中。 I will show you an example for a correctly code that sends email from phpmailer. 我将向您展示从phpmailer发送电子邮件的正确代码的示例。

require_once('../class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

Please make sure too that you are sending emails from a server already upload. 也请确保您正在从已经上传的服务器发送电子邮件。 If you are using virtual serves like XAMPP, review this page for enable the smtp configuration: How to configure XAMPP to send mail from localhost? 如果您正在使用XAMPP之类的虚拟服务,请查看此页面以启用smtp配置: 如何配置XAMPP以从本地主机发送邮件?

Greetings. 问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM