I'm trying to use PHPmailer to send mails. My webhost has said if the mail is relayed through their datacenter, no credentials are required. This is my code:
我正在尝试使用PHPmailer发送邮件。我的webhost已经说过,如果邮件是通过他们的数据中心中继的,则不需要凭据。这是我的代码:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtpgateway.webhost.com';
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
$mail->port = 25;
$mail->setFrom('info@mydomain.com', 'Test');
$mail->Subject = $email_subject;
$mail->Body = $email_body;
$mail->addAddress($email, $name);
$mail->isHTML(true);
if($mail->send())
{
echo "Success";
}
But I get this error when trying to send email:
但是在尝试发送电子邮件时出现此错误:
2018-08-21 10:07:03 CLIENT -> SERVER: MAIL FROM: info@mydomain.com
2018-08-21 10:07:03客户 - >服务器:邮件:info@mydomain.com
2018-08-21 10:07:03 SERVER -> CLIENT: 250 OK
2018-08-21 10:07:03服务器 - >客户端:250 OK
2018-08-21 10:07:03 CLIENT -> SERVER: RCPT TO:test@example.com
2018-08-21 10:07:03客户端 - >服务器:RCPT TO:test@example.com
2018-08-21 10:07:03 SERVER -> CLIENT: 550-Please turn on SMTP Authentication in your mail client. (mydomain.com)550-[10.100.15.115]:41032 is not permitted to relay through this server without550 authentication.
2018-08-21 10:07:03服务器 - >客户端:550 - 请在您的邮件客户端中打开SMTP身份验证。 (mydomain.com)550- [10.100.15.115]:41032不允许在没有550认证的情况下通过此服务器进行中继。
2018-08-21 10:07:03 SMTP ERROR: RCPT TO command failed: 550-Please turn on SMTP Authentication in your mail client (mydomain.com)550-[10.100.15.115]:41032 is not permitted to relay through this server without550 authentication.
2018-08-21 10:07:03 SMTP错误:RCPT TO命令失败:550-请在您的邮件客户端(mydomain.com)中打开SMTP身份验证550- [10.100.15.115]:41032不允许通过此进行中继服务器没有550认证。
3 个解决方案
#1
0
Try without any of the SMTP details as you potentially don't need to use SMTP from what your host has said.
尝试没有任何SMTP详细信息,因为您可能不需要使用主机所说的SMTP。
$mail->setFrom('info@mydomain.com', 'Test');
$mail->Subject = $email_subject;
$mail->Body = $email_body;
$mail->addAddress($email, $name);
$mail->isHTML(true);
if($mail->send())
{
echo "Success";
}
Worth a try, let me know if it doesn't work, but I'm guessing you don't need SMTP here.
值得一试,让我知道它是否不起作用,但我猜你这里不需要SMTP。
Check this out, similar issue: PHPmailer without using SMTP
检查一下,类似的问题:PHPmailer没有使用SMTP
#2
0
If this was purely about authentication, I would expect that first MAIL FROM
command to fail. The "relaying" message should be read like this:
如果这纯粹是关于身份验证,我希望第一个MAIL FROM命令失败。 “中继”消息应该如下所示:
(mydomain.com) is not permitted to relay through this server without authentication.
This suggests that this server doesn't host email for either the FROM or TO domains, i.e. it's relaying, and relaying without authentication makes it an open relay, which is a bad thing (unless it's inaccessible from outside). I would guess that you may need to use a different from domain for it to work without authentication, and look earlier in the SMTP transcript (at the response to EHLO
), which will show whether the server actually support authentication or not.
这表明该服务器不为FROM或TO域托管电子邮件,即它正在中继,并且没有身份验证的中继使其成为开放中继,这是一件坏事(除非它无法从外部访问)。我猜你可能需要使用一个不同的域才能在没有身份验证的情况下工作,并在SMTP转录本(在对EHLO的响应中)中查看,这将显示服务器是否实际支持身份验证。
SMTP is nearly always preferable to using the PHP mail() function; mail() is slower and less safe. All a sendmail binary does is open a synchronous SMTP connection to localhost anyway, so you're skipping an unnecessary process by doing it directly. Neither route makes any guarantees about speed of delivery - SMTP is a store-and-forward protocol, and operations can be extremely slow, which is why you want to hand off the job to a local mail server.
SMTP几乎总是优于使用PHP mail()函数; mail()速度较慢,安全性较低。所有sendmail二进制文件都会打开与localhost的同步SMTP连接,因此您可以通过直接执行此操作来跳过不必要的进程。这两种路由都不能保证交付速度 - SMTP是一种存储转发协议,操作速度极慢,这就是您希望将作业交给本地邮件服务器的原因。
#3
0
Please use this code .make sure you have given permission in Mail account from you want to send mail.
请使用此代码。确保您已在邮件帐户中获得了要发送邮件的权限。
My Account->Sign-in & security->Allow less secure apps: OFF
我的帐户 - >登录和安全 - >允许安全性较低的应用程序:关闭
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$mail->isSMTP();
$mail->Host = 'smtp.live.com';
$mail->SMTPAuth = true;
$mail->Username = 'mail@gmail.com';
$mail->Password = 'Password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom($details['from'], $details['from']);
if(is_array($details['to'])){
foreach ($details['to'] as $key => $value) {
$mail->addAddress($value['email'], $value['name']);
}
}else{
$mail->addAddress($details['to'], isset($details['name'])?:$details['to']);
}
$mail->isHTML(true);
$mail->Subject =$details['subject'];
$mail->Body =$details['body'];
$mail->send();
#1
0
Try without any of the SMTP details as you potentially don't need to use SMTP from what your host has said.
尝试没有任何SMTP详细信息,因为您可能不需要使用主机所说的SMTP。
$mail->setFrom('info@mydomain.com', 'Test');
$mail->Subject = $email_subject;
$mail->Body = $email_body;
$mail->addAddress($email, $name);
$mail->isHTML(true);
if($mail->send())
{
echo "Success";
}
Worth a try, let me know if it doesn't work, but I'm guessing you don't need SMTP here.
值得一试,让我知道它是否不起作用,但我猜你这里不需要SMTP。
Check this out, similar issue: PHPmailer without using SMTP
检查一下,类似的问题:PHPmailer没有使用SMTP
#2
0
If this was purely about authentication, I would expect that first MAIL FROM
command to fail. The "relaying" message should be read like this:
如果这纯粹是关于身份验证,我希望第一个MAIL FROM命令失败。 “中继”消息应该如下所示:
(mydomain.com) is not permitted to relay through this server without authentication.
This suggests that this server doesn't host email for either the FROM or TO domains, i.e. it's relaying, and relaying without authentication makes it an open relay, which is a bad thing (unless it's inaccessible from outside). I would guess that you may need to use a different from domain for it to work without authentication, and look earlier in the SMTP transcript (at the response to EHLO
), which will show whether the server actually support authentication or not.
这表明该服务器不为FROM或TO域托管电子邮件,即它正在中继,并且没有身份验证的中继使其成为开放中继,这是一件坏事(除非它无法从外部访问)。我猜你可能需要使用一个不同的域才能在没有身份验证的情况下工作,并在SMTP转录本(在对EHLO的响应中)中查看,这将显示服务器是否实际支持身份验证。
SMTP is nearly always preferable to using the PHP mail() function; mail() is slower and less safe. All a sendmail binary does is open a synchronous SMTP connection to localhost anyway, so you're skipping an unnecessary process by doing it directly. Neither route makes any guarantees about speed of delivery - SMTP is a store-and-forward protocol, and operations can be extremely slow, which is why you want to hand off the job to a local mail server.
SMTP几乎总是优于使用PHP mail()函数; mail()速度较慢,安全性较低。所有sendmail二进制文件都会打开与localhost的同步SMTP连接,因此您可以通过直接执行此操作来跳过不必要的进程。这两种路由都不能保证交付速度 - SMTP是一种存储转发协议,操作速度极慢,这就是您希望将作业交给本地邮件服务器的原因。
#3
0
Please use this code .make sure you have given permission in Mail account from you want to send mail.
请使用此代码。确保您已在邮件帐户中获得了要发送邮件的权限。
My Account->Sign-in & security->Allow less secure apps: OFF
我的帐户 - >登录和安全 - >允许安全性较低的应用程序:关闭
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$mail->isSMTP();
$mail->Host = 'smtp.live.com';
$mail->SMTPAuth = true;
$mail->Username = 'mail@gmail.com';
$mail->Password = 'Password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom($details['from'], $details['from']);
if(is_array($details['to'])){
foreach ($details['to'] as $key => $value) {
$mail->addAddress($value['email'], $value['name']);
}
}else{
$mail->addAddress($details['to'], isset($details['name'])?:$details['to']);
}
$mail->isHTML(true);
$mail->Subject =$details['subject'];
$mail->Body =$details['body'];
$mail->send();