想要使用SMTP发送邮件。但它没有用

时间:2016-04-12 14:05:54

标签: php mysql smtp

我尝试使用SMTP发送邮件,但它似乎无法正常工作。我收到了这个错误:

stringSMTP -> ERROR: Password not accepted from server: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required. 

以下发件人地址失败:

Sandakelumtharindu1994@gmail.com : MAIL not accepted from server,530,5.5.1 Authentication Required.
SMTP server error: 5.5.1 Authentication Required. 
ErrorThe following From address failed: sandakelumtharindu1994@gmail.com : MAIL not accepted from server,530,5.5.1 Authentication Required. 
SMTP server error: 5.5.1 Authentication Required.SMTP server error: 5.5.1 Authentication Required.

这是我的代码

approve.php

<?php
include('database_connect.php');

include "classes/class.phpmailer.php";
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->isHTML(true);
$mail->Username="sender@gmail.com";
$mail->Password="password";
$mail->SetFrom("sender@gmail.com");
$mail->Subject ="Credentials";
$mail->Body = "password";
$mail->AddAddress("reciever@gmail.com");

ini_set("SMTP", "smtp.rdslink.ro");
if(!$mail->Send()){
      echo "Error",$mail->ErrorInfo;
 }else{
      echo "message sent";
 }
?>

1 个答案:

答案 0 :(得分:0)

试试这个:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;          // Enable verbose debug output

$mail->isSMTP();                         // Set mailer to use    SMTP
$mail->Host = 'smtp1.example.com;';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                     // Enable SMTP   authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';     // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                     // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                             // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$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;
} else {
echo 'Message has been sent';
}

使用此 - https://github.com/PHPMailer/PHPMailer