Php 我正在尝试配置谷歌SMTP
我正在尝试配置google SMTP,但每次获取SMTP connect()时都失败。无法发送邮件。邮件程序错误:SMTP connect()失败错误,我尝试了多种解决方案,但此处没有任何效果。如何启用smtp邮件服务。这是我的密码Php 我正在尝试配置谷歌SMTP,php,phpmailer,Php,Phpmailer,我正在尝试配置google SMTP,但每次获取SMTP connect()时都失败。无法发送邮件。邮件程序错误:SMTP connect()失败错误,我尝试了多种解决方案,但此处没有任何效果。如何启用smtp邮件服务。这是我的密码 <html> <head> <meta charset="UTF-8"> <title>Send email via Gmail SMTP server in PHP</title>
<html>
<head>
<meta charset="UTF-8">
<title>Send email via Gmail SMTP server in PHP</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="main">
<h1>Send Email via Gmail SMTP Server in PHP</h1>
<div id="login">
<h2>Send Email</h2>
<hr/>
<form action="index.php" method="post">
<input type="text" placeholder="Enter your Gmail ID" name="email"/>
<input type="password" placeholder="Enter your Gmail Password" name="password"/>
<input type="text" placeholder="To : Email Id " name="toid"/>
<input type="text" placeholder="Subject : " name="subject"/>
<textarea rows="4" cols="50" placeholder="Enter Your Message..." name="message"></textarea>
<input type="submit" value="Send" name="send"/>
</form>
</div>
</div>
<?php
require 'phpmailer/PHPMailerAutoload.php';
if(isset($_POST['send'])){
$mail = new PHPMailer;
$mail->SMTPDebug = 2; //Enable SMTP debugging.
$mail->isSMTP();/*Set mailer to use SMTP*/
$mail->Host = 'smtp.gmail.com';/*Specify main and backup SMTP servers*/
$mail->Port = 587;
$mail->SMTPAuth = true;/*Enable SMTP authentication*/
$mail->Username = $email;/*SMTP username*/
$mail->Password = $password;/*SMTP password*/
$mail->SMTPSecure = 'tls';/*Enable encryption, 'ssl' also accepted*/
$mail->From = 'abc';
//$mail->FromName = $name;
$mail->addAddress('mmmmmm@gmail.com', 'demo');/*Add a recipient*/
//$mail->addReplyTo($email, $name);
/*$mail->addCC('cc@example.com');*/
/*$mail->addBCC('bcc@example.com');*/
$mail->WordWrap = 70;/*DEFAULT = Set word wrap to 50 characters*/
$mail->addAttachment('../tmp/' . $varfile, $varfile);/*Add attachments*/
/*$mail->addAttachment('/tmp/image.jpg', 'new.jpg');*/
/*$mail->addAttachment('/tmp/image.jpg', 'new.jpg');*/
$mail->isHTML(true);/*Set email format to HTML (default = true)*/
$mail->Subject = $subject;
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()){
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}else{
header("Location: http://cetpatechnologies.com/mail/index.php");
}
}
?>
</body>
在PHP中通过Gmail SMTP服务器发送电子邮件
在PHP中通过Gmail SMTP服务器发送电子邮件
发送电子邮件
你找到解决方案了吗?没有,这就是为什么在这里发布。当我注释掉下面几行时,它看起来像是在使用$mail->SMTPSecure='tls'$邮件->添加附件('../tmp/'.$varfile,$varfile);你看了吗?安迪调试输出?@veniseis是的!服务器->客户端:534-5.7.14请通过web浏览器和534-5.7.14登录,然后重试。534-5.7.14了解更多信息,请访问534 5.7.14 p74sm1721995lfp.68-gsmtp 2017-03-02 13:33:58 SMTP错误:密码命令失败:534-5.7.14