gpt4 book ai didi

php - 使用 PHPMailer 通过 SMTP 发送电子邮件

转载 作者:IT王子 更新时间:2023-10-28 23:59:43 24 4
gpt4 key购买 nike

我正在尝试使用 PHPMailer 发送 SMTP 电子邮件,但我一直收到此错误消息,有什么想法可以消除它吗?
我正在尝试通过端口 465 上的 SSL 进行连接。

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

有什么想法吗?

最佳答案

据我所知,您的代码一切正常。你的错误是:

SMTP Error: Could not authenticate.

这意味着您发送的凭据被 SMTP 服务器拒绝。确保主机、端口、用户名和密码正确。

如果您想使用 STARTTLS,请尝试添加:

$mail->SMTPSecure = 'tls';

如果您想使用 SMTPS (SSL),请尝试添加:

$mail->SMTPSecure = 'ssl';

请记住:

  • 一些 SMTP 服务器可以禁止来自“外部人员”的连接。
  • 一些 SMTP 服务器不支持 SSL(或 TLS)连接。

也许 this example可以提供帮助(GMail 安全 SMTP)。

[Source]

关于php - 使用 PHPMailer 通过 SMTP 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3618712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com