使用PHPMailer通过SMTP发送电子邮件 [英] Sending emails through SMTP with PHPMailer
问题描述
我正在尝试使用PHPMailer发送SMTP电子邮件,但我不断收到此错误消息,以及如何消除它的任何想法?
我正在尝试通过SSL在端口465上进行连接.
I'm trying to send SMTP e-mails using PHPMailer, but I keep getting this error message, any ideas how to get rid of it?
I'm trying to connect via SSL on port 465.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
Notice: fputs() [function.fputs]: send of 18 bytes failed with errno=32 Roura přerušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 494
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
Notice: fputs() [function.fputs]: send of 12 bytes failed with errno=32 Roura přerušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 212
SMTP -> ERROR: AUTH not accepted from server:
SMTP Error: Could not authenticate.
我的代码:
require_once('../library/PHPMailer_v5.1/class.phpmailer.php');
try{
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = SMTP_SERVER;
$mail->Port = SMTP_PORT;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPDebug = 2;
$mail->SetFrom(MAIL_ORDERS_ADDRESS, MAIL_ORDERS_NAME);
$mail->Subject = 'AMAZONEK.cz - objednávka číslo '.$_SESSION['orderId'];
$mail->MsgHTML('<b>Ahoj</b>');
$mail->AddAddress($_SESSION['user']['email'], $_SESSION['user']['name'].' '.$_SESSION['user']['surname']);
$mail->AddBCC(MAIL_ORDERS_ADDRESS, MAIL_ORDERS_NAME);
if(!$mail->Send()) throw new Exception($mail->ErrorInfo);
}
catch(Exception $e){
echo $e->getMessage();
}
常量定义:
define('SMTP_SERVER', 'smtp.ebola.cz');
define('SMTP_PORT', 465);
define('SMTP_USERNAME', 'myEmail@myDomain.tld');
define('SMTP_PASSWORD', '***CENSORED***');
define('MAIL_ORDERS_ADDRESS', 'myEmail@myDomain.tld');
define('MAIL_ORDERS_NAME', 'My Name');
有什么想法吗?
推荐答案
据我所知,您的代码一切正常.您的错误是:
As far as I can see everything is right with your code. Your error is:
SMTP错误:无法验证.
SMTP Error: Could not authenticate.
这意味着您已发送的凭据被SMTP服务器拒绝.确保主机,端口,用户名和密码正确.
Which means that the credentials you've sending are rejected by the SMTP server. Make sure the host, port, username and password are good.
如果要使用STARTTLS,请尝试添加:
If you want to use STARTTLS, try adding:
$mail->SMTPSecure = 'tls';
如果要使用SMTPS(SSL),请尝试添加:
If you want to use SMTPS (SSL), try adding:
$mail->SMTPSecure = 'ssl';
请记住:
- 某些SMTP服务器可以禁止来自外部"的连接.
- 某些SMTP服务器不支持SSL(或TLS)连接.
也许此示例可以帮助(GMail安全SMTP).
Maybe this example can help (GMail secure SMTP).
这篇关于使用PHPMailer通过SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!