Solved

PHPMailer error, can't send

Posted on 2013-06-25
9
717 Views
Last Modified: 2013-07-11
I've recently moved one of my websites to a new service provider and for some reason the forms have stopped working. My new provider is saying it's a problem with the script, but I'm using the same code on 2 other services and am having no such problems.

I'm using PHPMailer, authenticated via SMTP. The error I'm receiving is as follows:

SMTP -> ERROR: Failed to connect to server: Permission denied (13)SMTP Connect() failed. Message could not be sent.

Mailer Error: SMTP Connect() failed.

I've setup a very basic script as below for testing, but it's just not working on the new server, but yet the same script is working fine on another.

Can anyone tell me if it's something in the code or whether it's something my hosting provider needs to activate, I'm perplexed?

<?php
	ini_set('display_errors', 1);
	error_reporting(E_ALL);
	include_once('class.phpmailer.php');
		
	$mail             = new PHPMailer(); // defaults to using php "mail()"
	
	$body             = "<p><strong>Name:</strong> Name</p>";
	$body            .= "<p><strong>Email Address:</strong> Email</p>";
	$body            .= "<p><strong>Telephone:</strong> Tel</p>";
	
	$mail->From       = "sender@email.co.uk";
	$mail->FromName   = "sender";
	
	$mail->Subject    = 'Form';
	$mail->AltBody    = "Use an HTML compatible email viewer!";
	
	$mail->MsgHTML($body);
	
	$mail->AddAddress("email@email.co.uk");
		
	$mail->IsSMTP();
	$mail->SMTPAuth = "true";
	$mail->Username = "postmaster@server.co.uk"; 
	$mail->Password = "password"; 
	$mail->Host 	= "mail.server.co.uk";
	$mail->Port = 587;
	$mail->SMTPDebug = true;
	
	if(!$mail->Send())
	{
	   echo "Message could not be sent. <p>";
	   echo "Mailer Error: " . $mail->ErrorInfo;
	   exit;
	}
?>

Open in new window

0
Comment
Question by:djfenom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 29

Expert Comment

by:Jan Springer
ID: 39276326
Ask your provider why you are getting a permission denied when trying to connect to the SMTP server.  Looks like a mail server configuration issue.
0
 
LVL 4

Expert Comment

by:ScorchD
ID: 39276422
Looks like you need to provide log in credentials for your new server, probably something like
$mail->SMTPAuth = true; $mail->Username = ""; $mail->Password = "";

Open in new window

0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 39276440
The author does have SMTP AUTH configured in the script above.

The provider needs to identify why the authid if failing.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:ScorchD
ID: 39276451
Apologies I missed that, yes its a question for your provider.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39276549
Are you sending thru your new Host or some where else?  If it is somewhere else, does your new host allow outgoing connections thru port 587?
0
 

Author Comment

by:djfenom
ID: 39277290
The SMTP authentication goes to an external provider, so it's nothing to do with the new host. The exact same script works on different servers?
0
 
LVL 29

Accepted Solution

by:
Jan Springer earned 250 total points
ID: 39277921
The error message explicitly indicates that you are being refused when connecting to the server.  Either ports 25/587 are restricted and your new host is not in that list or auth account is not configured or the password configured is incorrect.

Your provider should be able to look at the mail configuration and in the mail logs to determine the problem.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 39278857
It only goes to an external provider if it is not blocked by the new host.  They are not required to let you connect to another SMTP provider.  Hosting companies often block services when they have had trouble like too much outgoing spam.
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 39278978
That's usually why SMTP AUTH is implemented -- as another avenue to allow authorized users to send outbound email.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question