【问题标题】:Authentication Error WHile Sending Mail in php在php中发送邮件时出现身份验证错误
【发布时间】:2015-11-01 07:50:41
【问题描述】:

我正在尝试通过 php 发送邮件.. 我也尝试过 php 的 mail 函数和 phpmailer() 函数。 但我无法发送 我也尝试通过设置端口号来更改 php.ini 中的设置。到 465,25 以及通过网络获得帮助的更多设置,但我的邮件仍然无法正常工作,我的代码

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>

<?php
date_default_timezone_set('asia/calcutta');

require_once('class.phpmailer.php');
$mail             = new PHPMailer();

$body             = "testing message";

$mail->IsSMTP(); // telling the class to use SMTP

$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = $_POST["u"];  // GMAIL username
$mail->Password   = $_POST["p"];            // GMAIL password

$mail->SetFrom($_POST["u"], 'First Last');

$mail->Subject = "hello";

    $mail->MsgHTML($body);

$address = $_POST["to"];
$mail->AddAddress($address, "info");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

</body>
</html>

我有另一个页面获取用户名、密码、发件人的电子邮件并在 dis 页面上获取 dem。我得到的错误是这样的:

邮件程序错误:以下发件人地址失败:s********@g***l.com:邮件未接受来自服务器,530,5.5.1 需要身份验证。了解更多信息,请致电 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp

SMTP 服务器错误:需要 5.5.1 身份验证。了解更多信息,请访问 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp

SMTP 服务器错误:需要 5.5.1 身份验证。了解更多信息,请访问 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp

有时我也会收到一条错误消息:

called mail() without being connected mailer error in php

请任何人帮助我.... 提前致谢

【问题讨论】:

标签: php email authentication phpmailer


【解决方案1】:

这是我的 phpMailer。 希望对你有帮助

require RB_ROOT.'/PHPMailer-master/PHPMailerAutoload.php';

define('GLAVNIMAIL', 'yoursMail@gmail.com');
define('PASSMAIL', 'xxxxxxxxx'); // enable 2 way notification on gmail to get this code

$mail = new PHPMailer;
//$mail->SMTPDebug = 4;
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = GLAVNIMAIL;  
$mail->Password = PASSMAIL;
$mail->From = GLAVNIMAIL;
$mail->FromName = 'Title From';
$mail->isHTML(true);
$mail->addAddress($email, 'Nov Korisnik');     // Add a recipient
//$mail->addReplyTo($email, $korpaime.' '.$korpaprezime);
//$mail->addCC('cc@example.com');
$mail->addBCC(GLAVNIMAIL);
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

$mail->Subject = 'Registracija korisnika '.$email;
$mail->Body = $bodyMail;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if (!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    die;
} else {
    echo 'OK poslat mail';

这是PHP MAILER的链接

希望对你有帮助

【讨论】:

  • $bodyMail 在这里面做了什么?
猜你喜欢
  • 2016-07-27
  • 1970-01-01
  • 2017-02-26
  • 2019-10-20
  • 2016-01-09
  • 2015-02-15
  • 1970-01-01
  • 2015-11-23
  • 1970-01-01
相关资源
最近更新 更多