2014-01-16 34 views
0

我撕我的头一会儿......PHPMailer的帮助 - 使用SMTP错误,但邮件是发送

使用PHPMailer的,从我的网站发送电子邮件。 我建立了我的网站上的HTML表单,和值从那里需要去到我的邮箱......你知道 - 标准:)

但我不断收到此错误: 邮件错误:SMTP连接( )失败。

当我打开SMTPDEBUG时,它是这样的: SMTP错误:无法连接到服务器:(0)SMTP连接()失败。邮件无法发送。邮件错误:SMTP连接()失败。

主机和端口是否正确,从我的提供商那里得到了详细信息。 有没有我丢失的东西,输入错误或被误解?

<?php 
    $email = $_REQUEST['email'] ; 
    $message = $_REQUEST['message'] ; 

    // here we use the php mail function 
    // to send an email to: 
    // [email protected] 
    mail("[email protected]", "Feedback Form Results",$message, "From: $email"); 

require 'PHPMailer/class.phpmailer.php'; 

$mail = new PHPMailer; 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.test.com';      // Specify main and backup server 
$mail->Port = 25; 
$mail->SMTPDebug = 2; 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';       // SMTP username 
$mail->Password = 'password';       // SMTP password 
$mail->SMTPSecure = 'ssl';       // 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'; 

?> 
+0

当然,我得到邮件时,我已经输入 电子邮件(“[email protected]”,“反馈表结果”,$消息,“从:$电子邮件”); 但现在我只是不recive邮件... – user2254488

回答

0

从我的理解了“SSL”设置SMTPSecure是直接连接的SSL,而“TLS”设置针对的是普通进行连接,随后升级为STARTTLS命令到SSL。有了端口25,你需要简单的连接,例如'TLS'。

相关问题