我正试图使用以下PHP代码发送电子邮件:
require("PHPMailer-master/src/PHPMailer.php");
require("PHPMailer-master/src/SMTP.php");
require("PHPMailer-master/src/Exception.php");
$from = "admin@mydomain.com";
$namefrom = "admin";
$mail = new PHPMailerPHPMailerPHPMailer();
$mail->isSMTP(); // by SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // user and password
$mail->Host = "mail.gandi.net";
$mail->Port = 110;
$mail->Username = $from;
$mail->Password = "Password123";
$mail->CharSet = 'UTF-8';
// $mail->SMTPSecure = ""; // options: 'ssl', 'tls' , ''
$mail->setFrom($from,$namefrom); // From (origin)
$mail->addCC($from,$namefrom); // There is also addBCC
$mail->Subject = "Some subject";
$mail->AltBody = "Altenrate";
$mail->Body = "Heyheyhey";
$mail->isHTML(false); // Set HTML type
$mail->addAddress("hello@hotmail.com", "hello@hotmail.com");
if($mail->send())
{
echo "ok sent";
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
问题是,当使用这个代码时,它需要很长时间才能加载,并最终向我显示这个错误:
2018-12-09 20:50:24 CLIENT -> SERVER: EHLO www.mydomain.be
2018-12-09 20:53:24 SMTP ERROR: EHLO command failed: -ERR Unknown command.-ERR Disconnected for inactivity.
2018-12-09 20:53:24 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
有人能解释一下问题是什么以及如何解决吗?
谢谢!
您的设置错误,根据:https://docs.gandi.net/en/gandimail/standard_email_settings/index.html
应该是
Outgoing (SMTP) server name: mail.gandi.net
Port: 25, 465 (with SSL) or 587 (with STARTTLS)
TLS or SSL: yes
SMTP Authentication: yes, using the same settings as for the POP / IMAP account
你好,traducerad,
$mail->isSMTP(); // by SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // user and password
$mail->Host = "mail.gandi.net";
$mail->Port = 110;
$mail->Username = $from;
$mail->Password = "Password123";
// $mail->SMTPSecure = "";
端口110用于传入POP通信
我想你想通过SMTP发送一封电子邮件。
传出(SMTP(服务器名称:mail.gandi.net
端口:25465(带SSL(或587(带STARTTLS(
TLS或SSL:是
SMTP身份验证:是,使用与POP/IMAP帐户相同的设置
来自gandi.net 的常见问题解答