1

I'm trying to use PHPMailer to send emails from a contact form. Once submitted, the server doesn't respond for more than 5 minutes, then results in ERROR 405 Not Allowed - ngnix.

I'm using SMTP Auth from webmaster@mydomain.com, and the SMTP server is located at voyager.websitewelcome.com. I thought, "Could it be because of the cross-domain submission, even though this isn't AJAX and is all PHP?"

Nope, see answer below:

mail = new PHPMailer;

$mail->isSMTP();
$mail->Host = 'voyager.websitewelcome.com';
$mail->SMTPAuth = true;
$mail->Username = 'webmaster@mydomain.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls'; //<---- THIS is the problem
$mail->Port = 465;

$mail->setFrom('webmaster@mydomain', 'My Company Kiosk');
$mail->addAddress('me@mydomain.com', 'My Name');

$mail->isHTML(true);

$mail->Subject = 'New Lead from My Company';
$mail->Body    = '<b>test</b> html'; //$body;
$mail->AltBody = 'test text';


try {
  $mail->send();
  //echo $output;
}
catch (phpmailerException $e) {
  echo $e->errorMessage();
} catch (Exception $e) {
  $e->getMessage();
}
Dexter
  • 795
  • 2
  • 13
  • 27

2 Answers2

2

It's not that the server doesn't allow TLS, it's that you're trying to use explicit SSL (SMTP+STARTTLS == 'tls' in PHPMailer) on a port expecting implicit SSL (SMTPS). You could also have fixed it (in a way not deprecated since 1998) by setting $mail->Port = 587;, which is what the documentation suggests (look under "using encryption").

Incidentally your error trapping will not work because PHPMailer does not throw exceptions by default, you need to pass true to the constructor to enable them, like this:

$mail = new PHPMailer(true);
Synchro
  • 35,538
  • 15
  • 81
  • 104
  • Thanks for the updated answer! This is much more informative than my accidental discovery. My SMTP server setup suggestion claims to accept both TLS and SSL on that port, so I didn't think to try port 587. I'll give that a try since TLS is more secure and this involves customers' personal information. If that doesn't work, I'll give them a call and see if the guy knows anything about the port configuration. And thanks for the update about error trapping, I completely missed that. – Dexter Feb 02 '16 at 18:05
0

In the middle of writing this question, "TLS" caught my eye. I never thought to change this, and my SMTP server does not allow TLS!

I've read through so many posts trying to figure this out. I thought someone ought to post a possible answer!

$mail->SMTPSecure = 'ssl';
Dexter
  • 795
  • 2
  • 13
  • 27