dqwn64004 2015-08-09 07:31
浏览 37

身份验证错误WHile在php中发送邮件

i am trying to send a mail through php.. i have tried through php's mail function and phpmailer() function too. but i'm not able to send it i have tried by changing settings in php.ini tooby setting port no. to 465,25 and some more settings by getting help over the net but still my mail is not working, my code

<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>

i have an other page taking username,password,sender's email and getting dem on dis page.and the error i am getting is something like this:

Mailer Error: The following From address failed: s********@g***l.com : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp

SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 https:/support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp

SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 https:/support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp

sometimes i also get an error message saying:

called mail() without being connected mailer error in php

please help me anyone.... And Thanks in advance

  • 写回答

1条回答 默认 最新

  • doufeng5059 2015-08-09 11:17
    关注

    This is my phpMailer. Hope it will help you

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

    This is link for PHP MAILER

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测