Reputation: 465
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:
$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('[email protected]', '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: [email protected]
2018-08-21 10:07:03 SERVER -> CLIENT: 250 OK
2018-08-21 10:07:03 CLIENT -> SERVER: RCPT TO:[email protected]
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 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.
Upvotes: 4
Views: 2692
Reputation: 48
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 = '[email protected]';
$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();
Upvotes: 0
Reputation: 37810
If this was purely about authentication, I would expect that first MAIL FROM
command to fail. The "relaying" message should be read like this:
(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.
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.
Upvotes: 1
Reputation: 1304
Try without any of the SMTP details as you potentially don't need to use SMTP from what your host has said.
$mail->setFrom('[email protected]', '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.
Check this out, similar issue: PHPmailer without using SMTP
Upvotes: 0