Php 邮件程序错误SMTP connect()失败
我需要帮助我不断地犯这个错误, 无法发送邮件。邮件程序错误:SMTP connect()失败 这是我的密码Php 邮件程序错误SMTP connect()失败,php,Php,我需要帮助我不断地犯这个错误, 无法发送邮件。邮件程序错误:SMTP connect()失败 这是我的密码 <?php require 'PHPMailerAutoload.php'; $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP();
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail@gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mymail@gmail.com', 'Mailer');
$mail->addAddress('sendtomail@gmail.com', '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';
}
?>
您的代码是正确的,除了几件事。我编辑了你的代码,消息被发送了。还要检查您的用户名和密码是否正确,就像我尝试使用用户名和密码一样。还要检查是否包含class.phpmailer.php
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail@gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mymail@gmail.com', 'Mailer');
$mail->addAddress('sendtomail@gmail.com', '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';
}
?>
您的代码是正确的,除了几件事。我编辑了你的代码,消息被发送了。还要检查您的用户名和密码是否正确,就像我尝试使用用户名和密码一样。还要检查是否包含class.phpmailer.php
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail@gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mymail@gmail.com', 'Mailer');
$mail->addAddress('sendtomail@gmail.com', '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';
}
?>
您在php.ini中启用了smtp
和端口吗?我不确定,但我确实配置了php.ini smtp=mail.gmail.com smtp\u port=587和sendmail.ini smtp\u server=smpt.gmail.com;smtp端口(通常为25)smtp_port=587您是否在php.ini中启用了smtp
和port
?我不确定,但我确实配置了php.ini smtp=mail.gmail.com smtp_port=587和sendmail.ini smtp_server=smpt.gmail.com;smtp端口(通常为25)smtp_port=587感谢您的帮助Aarju Mishra女士,在应用您的代码挖掘发生的新错误后。。这是:2016-04-20 07:13:51客户端->服务器:EHLO本地主机2016-04-20 07:13:51客户端->服务器:STARTTLS 2016-04-20 07:13:51客户端->服务器:EHLO本地主机2016-04-20 07:13:51客户端->服务器:身份验证登录2016-04-20 07:13:52客户端->服务器:bm92b2hvdgvsb3jtb2naz21hawuy29t 2016-04-20 07:13:52客户端->服务器:bm92b2hvdGVs 2016-04-04-2007:13:52 SMTP错误:密码命令失败:534-5.7.14请通过您的web浏览器和534-5.7.14登录,然后重试。这意味着您的用户名和密码不正确。请在gmail中创建新的电子邮件id,并将其作为用户名并写入密码。当我试图在编辑后运行你的代码时,它会抛出相同的错误,当我提供正确的用户名和密码时,会显示消息sentHey Doy you checked??我已成功发送邮件。我真的非常感谢您的帮助Aarju Mishra女士^ ^感谢您的帮助Aarju Mishra女士,在应用您的代码挖掘后,发生了一个新的错误。。这是:2016-04-20 07:13:51客户端->服务器:EHLO本地主机2016-04-20 07:13:51客户端->服务器:STARTTLS 2016-04-20 07:13:51客户端->服务器:EHLO本地主机2016-04-20 07:13:51客户端->服务器:身份验证登录2016-04-20 07:13:52客户端->服务器:bm92b2hvdgvsb3jtb2naz21hawuy29t 2016-04-20 07:13:52客户端->服务器:bm92b2hvdGVs 2016-04-04-2007:13:52 SMTP错误:密码命令失败:534-5.7.14请通过您的web浏览器和534-5.7.14登录,然后重试。这意味着您的用户名和密码不正确。请在gmail中创建新的电子邮件id,并将其作为用户名并写入密码。当我试图在编辑后运行你的代码时,它会抛出相同的错误,当我提供正确的用户名和密码时,会显示消息sentHey Doy you checked??我已成功发送邮件。我真的很感谢你的帮助Aarju Mishra女士^_^