[英]phpmailer working on localhost but when i upload it on my ubuntu server it gives me error and mail is not sending(I am using gmail smtp)
<?php
if(isset($_POST['sendmail'])) {
require 'PHPMailerAutoload.php';
require 'credential.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // 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 = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom(EMAIL, 'litdeveloper');
$mail->addAddress($_POST['email']); // Add a recipient
$mail->addReplyTo(EMAIL);
// print_r($_FILES['file']); exit;
for ($i=0; $i < count($_FILES['file']['tmp_name']) ; $i++) {
$mail->addAttachment($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]); // Optional name
}
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = '<div style="border:2px solid red;">This is the HTML message body <b>in bold!</b></div>'.$_POST['message'];
$mail->AltBody = $_POST['message'];
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
?>
How can I resolve this error i also tried after commenting this $mail->isSMTP() but it is not working.如何解决此错误,我在评论此 $mail->isSMTP() 后也尝试过,但它不起作用。 It is working properly on XAMP Email id and password is correct what should i do plz help me out
它在 XAMP 电子邮件 ID 上正常工作,密码正确,我该怎么办,请帮帮我
The most important thing to do when you have an error message is read what it says , so when it says:当您收到错误消息时,最重要的事情是阅读它所说的内容,因此当它说:
534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 g206sm18050557pfb.178 - gsmtp
It should not come as a surprise that the way to fix this is to log in to your gmail account using a normal web browser, and follow that link if you want to find out why they ask you to do this.解决此问题的方法是使用普通网络浏览器登录您的 Gmail 帐户,如果您想了解他们要求您这样做的原因,请点击该链接,这不足为奇。
For other information, you should follow the link to the troubleshooting guide that appears in your debug output (and you reposted here twice!), in particular this part , which addresses the exact problem you have.有关其他信息,您应该点击调试输出中出现的故障排除指南的链接(并且您在此处重新发布了两次!),特别是这部分,它解决了您遇到的确切问题。
Apart from the fact that you're using a very old version of PHPMailer, your config and code looks correct;除了您使用的是非常旧版本的 PHPMailer 之外,您的配置和代码看起来是正确的; that's not where the problem lies.
这不是问题所在。
Incidentally, you should now change your gmail password as it is displayed in an easily decoded format in your debug output.顺便说一句,您现在应该更改您的 gmail 密码,因为它在调试输出中以易于解码的格式显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.