PHPMailer帮助-收到SMTP错误,但邮件已发送 [英] PHPMailer HELP - Getting SMTP error but mail is send

查看:133
本文介绍了PHPMailer帮助-收到SMTP错误,但邮件已发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我马上把头扯开...

I'm ripping my head off in a moment...

使用PHPmailer从我的网站发送电子邮件.我已经在我的网站上创建了一个HTML表单,并且其中的值需要转到我的邮件中……您知道-标准:)

Using PHPmailer to send a email from my site. I have created a HTML-form on my website, and the values from there needs to go to my mail... You know - standard :)

但我一直收到此错误:邮件错误:SMTP connect()失败.

But I keep getting this error : Mailer Error: SMTP connect() failed.

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

When I have turned SMTPDEBUG on it goes like this: SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

主机和端口是正确的,从我的提供商那里获得了详细信息.有什么我想念的东西,输入错误或被误解了吗?

The host and port is correct, got the details from my provider.. Is there something i'm missing, typed in wrong or misunderstood?

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

  // here we use the php mail function
  // to send an email to:
  // you@yourdomain.com
  mail( "info@recive.com", "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 = 'info@recive.com';                            // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'info@recive.com';
$mail->FromName = 'Mailer';
//$mail->addAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->addAddress('info@recive.com');               // Name is optional
//$mail->addReplyTo('info@recive.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$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';

?>

推荐答案

据我了解,SMTPSecure的'ssl'设置用于直接ssl连接,而'tls'设置用于普通连接,然后使用STARTTLS命令.使用端口25时,您需要进行简单连接,例如'tls'.

From my understanding the 'ssl' setting for SMTPSecure is for direct ssl connect, while the 'tls' setting is for plain connect followed by upgrading to SSL with the STARTTLS command. With port 25 you need plain connect, e.g. 'tls'.

这篇关于PHPMailer帮助-收到SMTP错误,但邮件已发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆