I got some problem when I try to use PHPMailer code.
This code still works on Oct/2017 but not work since Dec/2017 to now.
I tried to find other similar question but time seems too odd, or it doesn't help.
I didn't change any code inside since I finished.
but error appeared when time passed.
And I got this error:
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
when I try to find it on troubleshotting, it says it might cause by localhost.
Here is my code:
function mailsend($email,$accepter,$title,$content){
include_once("../lib/PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->CharSet = "utf-8";
$mail->Encoding = "base64";
$mail->WordWrap = 50;
$mail->Username = "myaccount#gmail.com";
$mail->Password = "mygmail_account_password";
$mail->From = "sender#gmail.com";
$mail->FromName = "sender_name";
$mail->Subject = $title;
$mail->IsHTML(true);
$mailList =
array(
array($email,$accepter)
);
foreach ($mailList as $receiver) {
$mail->AddAddress($receiver[0], $receiver[1]);
$mail->Body = $content;
if($mail->Send()) {
// echo"<script>alert('success_sended');</script>";
} else {
echo $mail->ErrorInfo;
echo "<br>";
}
$mail->ClearAddresses();
}
}
If I want to change some code to make it work again
where can I start?
Cheers for taking a look.
I had the same Error but with Yandex,try adding the following:
$mail->SMTPKeepAlive = true;
$mail->Mailer = “smtp”; // don't change the quotes!
See more here https://stackoverflow.com/a/48010266
Related
I have a really simple PHP code for sending emails. The page is loading without any errors but it doesn't seem to do anything.
also, I am new to PHP and I don't really know how to debug this stuff.
I'll really appreciate a little help (: thank you!
<?php
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure ='ssl';
$mail->Host = 'smtp.gmail.com';
$mail->port = '456';
$mail->isHtml();
$mail->Username = 'lagofbot#gmail.com';
$mail->Password = 'lago9876543s';
$mail->Subject = 'Hello';
$mail->Body = "test";
$mail->From = 'no-replay';
$mail->FromName = 'no-replay';
$mail->AddAddress('mrxvr123#gmail.com');
$mail->send();
?>
change your code like this and see if it will show you any errors
$mail = new PHPMailer();
try {
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure ='ssl';
$mail->Host = 'smtp.gmail.com';
$mail->port = '456';
$mail->isHtml();
$mail->Username = 'lagofbot#gmail.com';
$mail->Password = 'lagofbot258258#258258';
$mail->Subject = 'Hello';
$mail->Body = "test";
$mail->From = 'no-replay';
$mail->FromName = 'no-replay';
$mail->AddAddress('mrxvr123#gmail.com');
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
Try with this
require __DIR__.'../phpmailer/src/PHPMailer.php'; //configure according your files
require __DIR__."./phpmailer/src/Exception.php";
require __DIR__."../phpmailer/src/SMTP.php";
$mail = new \PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->isSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->Username = ""; //GMAIL ACCOUNT EMAIL ID
$mail->Password = ""; // GMAIL ACCOUNT PASSWORD
$mail->SetFrom("",''); // FROM THIS MAIL ID & SET AS DEFINE IN SECOND PARAMETER
$mail->addAddress($email); // `TO` FIELD IN MAIL
$mail->IsHTML(true);
if (!$mail->Send()) {
return true;
} else {
return false;
}
And don't forget to enable less secure apps if you use gmail.
Hope this helps :)
I am trying to configure PHPMailer in order to have it working ona Windows IIS server using php scripts.
The application I have is written in PHP so we expected we could easily use PHPMailer to send emails.
Well, that doesn't work.
We have tried configuring it as SMTP, but we still get error in configuration.
Here it is our script:
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 1;
//$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "account#gmail.com";
$mail->Password = "gmailPWD";
$mail->setFrom('info#website.com', 'The Website');
$mail->addAddress($to, '');
$mail->Subject = $subject;
$mail->msgHTML($message);
if (!$mail->send()) {
$errors = "Errori Mailer: " . $mail->ErrorInfo;
} else {
$errors = "<h5>Sent!</h5>";
}
Any clue? How can that be used on windows server?
Thank you
EDIT
So, it was a problem of Gmail and its security settings. I followed this post: https://stackoverflow.com/a/25175234/1873501 and everything went smooth!
I just wanted to share it.
You've downloaded and extracted the class I am assuming. Maybe you're not autoloading? Make sure you include:
require '/path/to/PHPMailerAutoload.php';
It should be fine on IIS/Windows Server. See some of the examples here in the documentation (and in the examples folder): https://github.com/PHPMailer/PHPMailer
Also, if you are getting any errors make sure you list them so we know how to help you further.
function sendMail($request) {
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'yourmail#gmail.com;
$mail->Password = 'yourgamilPass';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('yourgmail#gmail.com', 'Title');
$mail->addAddress(emailsendingto#gmail.com);
$mail->addReplyTo('yourgmail#gmail.com');
$mail->isHTML(true);
$mail->Subject = '$the subject of the e-mail';
$mail->Body = 'The body of the email';
$mail->AltBody = 'Alternative'; // this is mostly sent to your own mail
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
I am trying to build a mail function with php, but it's justing showing "Invalid address:" after execute. Pleas help.
Below is my code:
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'myemail#gmail.com';
$mail->Password = 'mypassword';
$mail->From = "myemail#gmail.com";
$mail->FromName = "Web Site";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addAddress('myfriend#gmail.com');
$mail->AddReplyTo('myfriend#gmail.com');
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
Try This
Please write the below line.
$mail->CharSet = "UTF-8"; // To support special characters in SMTP mail
//$mail->SMTPDebug = 2; Comment this line of code
I hope this will help you. Good Luck
I have some troubles with my sending loop with PHP Mailer:
<?php
foreach ($packTabCible as $key => $pack) {
// PHPMailer
$mail = new PHPMailer;
$mail->Mailer = "smtp";
$mail->isSMTP();
$mail->SMTPKeepAlive = true;
$mail->SMTPAuth = true;
$mail->Encoding = '8bit';
$mail->SMTPDebug = 3;
$mail->setLanguage('fr', './PHPMailer/language/');
$mail->CharSet = 'UTF-8';
$mail->WordWrap = 10000;
$mail->Host = $hostname;
$mail->Username = $username;
$mail->Password = $pass;
$mail->SMTPSecure = $tls;
$mail->Port = $port;
$mail->FromName = utf8_decode($from_name);
$mail->isHTML(true);
$mail->Subject = utf8_decode($sujet);
$mail->From = $from_mail;
foreach ($pack as $email => $md5) {
$mail->addAddress($email);
$header = str_replace("#miroir#", $link_miroir, $ip_header_html);
$footer = str_replace("#lien#", $link_unsub, $ip_footer_html);
$content = str_replace("<body>", "<body>".$header, $message);
$content = str_replace("</body>", $footer.'</body>', $content);
$content = str_replace("#email#", $email, $content);
$mail->Body = $content;
$mail->AltBody = str_replace("#miroir#", $link_miroir, utf8_decode($ip_header_txt))
. $txt
. str_replace("#lien#", $link_unsub, $ip_footer_txt);
$mail->send();
$mail->clearAddresses();
usleep($timer);
}
$mail->SmtpClose();
usleep(5000000);
}
?>
I'm 100% sure of the validity of the parameters I send to PHPMailer.
There is 2 loops, and I reset the connexion after each loop of $packTabCible with $mail->SmtpClose();
But, PHPMailer return the error:
The following From address failed: news#my-domain.com : MAIL FROM command failed,0 ok
,
2,SMTP server error: MAIL FROM command failed Detail: 0 ok
SMTP code:
2SMTP server error: MAIL FROM command failed Detail: 0 ok
SMTP code:
2
But news#my-domain.com is the good one so the problem is elsewhere...
If someone have an idea, big thanks
I used phpgmailer to send emails and it was working smoothly. Today I tested my project and it's not working now.
<?php
require_once('class.phpgmailer.php');
$mail = new PHPGMailer();
$mail->Username = 'username#gmail.com';
$mail->Password = '********';
$mail->From = 'username#gmail.com';
$mail->FromName = "<blah>";
$mail->Subject = 'something';
$mail->AddAddress('xyz#gmail.com');
$mail->Body = "Hello Sir"."\n"."
Your Password is : ."."";
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Send();
if(!$mail->Send())
{
echo 'Message could not be sent.' ;
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
I suggest you download PHPMailer and try this code:
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "from#gmail.com";
$mail->Password = "****";
$mail->FromName = "Sender name";
$mail->Subject = "test";
$mail->Body = "Test body";
$mail->AddAddress('sender#mail.com');
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message has been sent";
}
#goose is right, remove the first $mail->Send() and leave the one in the if statement. If the From address is the same as the username email, then you don't need that either as it will take it from your gmail account.
Try that and see if it works.
EDIT: try adding the following;
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'email#gmail.com';
$mail->Password = 'password';
Try that and if there are errors, then it should give you more detail.
EDIT2: If that doesn't work then I suggest trying PHPMailer instead of PHPGmailer - and follow the tutorial here: http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
Please, make sure:
$mail->Username is equal to $mail->From, and is correct
$mail->Password is correct
$mail->FromName does not contain "<" and ">" characters; just try $mail->FromName = 'Test';