Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPMailer not sending mail #2005

Closed
nandhini-rajanayagam opened this issue Mar 5, 2020 · 3 comments
Closed

PHPMailer not sending mail #2005

nandhini-rajanayagam opened this issue Mar 5, 2020 · 3 comments

Comments

@nandhini-rajanayagam
Copy link

nandhini-rajanayagam commented Mar 5, 2020

I can't able to send mail using phpmailer from windows server 2012 , but i can able to send from local machine using local server. Can any body help me?

require("PHPMailer/PHPMailerAutoload.php");
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "mail.company.in";
$Mail->Port = 25;
$Mail->SMTPDebug = 6; // 2 to enable SMTP debug information
$Mail->SMTPAuth = false; // enable SMTP authentication
$Mail->AuthType = 'PLAIN'; // enable SMTP authentication
$Mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$Mail->Username = "noreply.company";
$Mail->Password = "456546";
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = '[email protected]';
$Mail->FromName = 'Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line

$Mail->AddAddress( $to ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $content;
$Mail->AltBody = $content;
$Mail->Send();
$Mail->SmtpClose();

if ( $Mail->IsError() ) { // ADDED - This error checking was missing
return FALSE;
}
else {
return TRUE;
}

I got the following error message,

2020-03-05 08:51:24 SERVER -> CLIENT: 220 company.in ESMTP Postfix
2020-03-05 08:51:24 CLIENT -> SERVER: EHLO 59.145.185.21
2020-03-05 08:51:24 SERVER -> CLIENT: 250-company.in 250-PIPELINING250-SIZE 92274688250-VRFY250-ETRN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2020-03-05 08:51:24 CLIENT -> SERVER: STARTTLS
2020-03-05 08:51:24 SERVER -> CLIENT: 502 Command not implemented
2020-03-05 08:51:24 SMTP ERROR: STARTTLS command failed: 502 Command not implemented
SMTP Error: Could not connect to SMTP host.
2020-03-05 08:51:24 CLIENT -> SERVER: QUIT
2020-03-05 08:51:24 SERVER -> CLIENT: 221 2.0.0 Bye
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@r0073rr0r
Copy link
Contributor

r0073rr0r commented Mar 5, 2020

domain doesn`t exist (mail.company.in: Non-existent domain), if mail server is in your localhost, try using localhost, also for all information's you have link in exception:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

P.S. Reduct/remove password, don`t ever send your password (credentials).

@Synchro
Copy link
Member

Synchro commented Mar 5, 2020

You're doing a whole load of things wrong, but the fundamental thing is that your server does not support encryption. That's bad. As for the other things:

require("PHPMailer/PHPMailerAutoload.php");

This means you're using a very old version. Upgrade.

$Mail->SMTPDebug = 6; // 2 to enable SMTP debug information

There is no debug level 6. You only need 2 to diagnose this problem.

$Mail->SMTPAuth = false; // enable SMTP authentication
$Mail->AuthType = 'PLAIN'; // enable SMTP authentication

You're disabling authentication (so the AuthType doesn't matter), then later providing a user name and password unnecessarily.

$Mail->SMTPOptions = array(

Don't do this; it's dangerous. Fix your server instead.

$Mail->Encoding = '8bit';

You don't need to set this.

$Mail->ContentType = 'text/html; charset=utf-8\r\n';

Your'e trying to undo things that PHPMailer is doing for you; don't do this as it will likely break your messages. Your'e already calling isHTML(), which takes care of content-type for you, and correctly.

$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line

WordWrap is not the same thing as line length, and only applies to plain text messages. You don't need this, and it's not doing what you think anyway.

if ( $Mail->IsError() ) { // ADDED - This error checking was missing

Don't check for errors like this. Check the return vale of send(), as all the examples do.

@Synchro Synchro closed this as completed Mar 5, 2020
@nandhini-rajanayagam
Copy link
Author

domain doesn`t exist (mail.company.in: Non-existent domain), if mail server is in your localhost, try using localhost, also for all information's you have link in exception:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

P.S. Reduct/remove password, don`t ever send your password (credentials).

domain doesn`t exist (mail.company.in: Non-existent domain), if mail server is in your localhost, try using localhost, also for all information's you have link in exception:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

P.S. Reduct/remove password, don`t ever send your password (credentials).

i just use dummy domains with dummy user id password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants