Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

PHPMailer

Hello Experts,

I just downloaded PHPMailer from https://github.com/PHPMailer/PHPMailer  and copied/pasted the code from the "a simple example" section, but I keep getting:

Message could not be sent.Mailer Error: SMTP connect() failed.

Thank you
0
APD_Toronto
Asked:
APD_Toronto
  • 6
  • 6
  • 6
  • +1
3 Solutions
 
GaryCommented:
Did you set the correct port? (assuming your credentials are correct)
0
 
APD_TorontoAuthor Commented:
yes, I transferred my credentials from my ASP CDO SYS, however, there are two hazy  issues

1. My password has some reserved characters like pa$$word, so I am using

$mail->Password = "pa\$\$word";

2. My CDO SYS has the following

.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

I am assuming this is equivalent to $mail->SMTPSecure, but I am not sure what is 1 equivalent to?
0
 
GaryCommented:
1. Use
$mail->Password = 'pa$$word'; // note the apostrophes instead, easier to read

2. Not sure, too many years since I last used it,

The port is the likely culprit, if you copied it verbatim, as the error is it cannot even connect to the server
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Marcus BointonCommented:
There are quite a few reasons why this can happen, most commonly just basic connectivity issues. :: Competing site link removed - Gary ::

In a double-quoted string, you don't need to escape characters other than " in your password, so don't do that. There's not really any such thing as a "reserved character" other than control characters (like tab and line breaks).

That `smtpauthenticate` mention looks like it wants authentication, not encryption, which is what SMTPSecure controls. I suspect this should translate to `$mail->SMTPAuth = true;`, and you will also need to provide Username and Password properties (as in the readme example) for it to be able to log in.

(I'm the maintainer of PHPMailer)
0
 
APD_TorontoAuthor Commented:
I removed the escape characters from my password and everything else is single-quoted, but the error remains the same.

I am using $mail->Port = 2;, which may seem odd, but that is what would in CDOSYS

Any further feedback would be appreciated.
0
 
GaryCommented:
And that is open in the firewall and PHP has access to it, it may be restricted only to the CDO component using it?
0
 
Marcus BointonCommented:
That port number is extremely likely to be wrong, or a correct value for an unrelated parameter. Typical values will be 25, 465, 587, and occasionally you'll see 2525, 2500 etc.
0
 
APD_TorontoAuthor Commented:
I have tried all port numbers from above, the result is the same
0
 
GaryCommented:
Firewall...?
0
 
APD_TorontoAuthor Commented:
I am emailing the hosting company now, will keep you posted.

If any other ideas in the mean time, please share.
0
 
Marcus BointonCommented:
If you saw the link I originally posted, it had a troubleshooting sequence for exactly this problem. The key is to test outside PHPMailer before trying to fix it inside. Check that your DNS is working, that the target SMTP server responds to pings and you can telnet to it.
0
 
MurfurFull Stack DeveloperCommented:
Firstly...

I would seriously recommend you change your SMTP password to something considerably more secure than 'pa$$word'!
The smtpauthenticate = 1 in your CDO is NOT equivalent to $mail->SMTPSecure.
It specifies the authentication method to be used and 1 means that in this case it is plain text with a username and password, as opposed to 0 (no authentication) or 2 (NTLM).

The equivalent would be $mail->SMTPAuth = true;

$mail->SMTPSecure is used to tell PHPMailer to use a secure connection and the options art "tis" or "ssl" e.g.
$mail->SMTPSecure = "ssl";

if you didn't have a secure connection in CDO then just comment out or remove the $mail->SMTPSecure line.

Have you tried turning on the debug output with $mail->SMTPDebug = 3 which will report the connection status and details of the attempted data transfer.

All that said and if you have correctly transferred equivalent settings from CDO to PHPMailer it should all work

Can you post your CDO connection settings?

Another Q - are you making the SMTP request form the same host as the CDO script or a different one. If the latter,  then check that it is not blocked by a firewall or other restriction.
0
 
Marcus BointonCommented:
Reposting what others have already said isn't very helpful.
0
 
MurfurFull Stack DeveloperCommented:
Depends on your perspective! In my defence your Honour, when I started there weren't any responses but then children being sick everywhere distracted me somewhat...
0
 
APD_TorontoAuthor Commented:
I hear back from the hosting provider and they changed some credentials, and worked. However, I have the following question for you

1. I had my  $mail->Host = 'mail.mydomain.com', but my script is at 'test.mydomain.com', so they changed this to 'test.mydomain.com'. Does this mean the domain were my script resides, and if I wanted it in my primary domain, it wont just be 'mydomain.com'?

2. For $mail->Username I was using 'donotreply@myotherdomain.com' with appropriate password, but they changed it to an address @mydomain.com. Does this means that I cannot use an address to authenticate from another domain (same server)?

3. I realize that under $mail->FromName I can have any email address,  but when the email is received, it says that address followed by <root@localhost>.  Can <root@localhost> be changed?

4. Even though this script works with the changed credentials on the server, it doesn't work from my local machine. Even though not important, it would be nice.

Thank you
0
 
Marcus BointonCommented:
1. The Host value is the FQDN of your mail server, not necessarily the same server that your script is running on. It would be unusual for the mail server to use just the bare domain, and not some hostname like mail, test etc.

2. Authentication within a single mail server generally isn't that bothered about which domain you authenticate with (certainly mine isn't), so long as you can authenticate, it will allow you to relay mail through it.

3. There is a From property as well as FromName - also look at the setFrom method.

4. That sounds like a connectivity problem.
0
 
GaryCommented:
1. This is the mail server address, not your address

2. This will depend on what the mail server is expecting, it won't accept an email address it doesn't recognise (at least it shouldn't)

3. Can be anything you like, doesn't matter

4. Check the firewall, your port is unusual
0
 
APD_TorontoAuthor Commented:
@Gary
>>3. Can be anything you like, doesn't matter
How?
0
 
GaryCommented:
It's just the From Name - could be your name, or anything.
0
 
Marcus BointonCommented:
$mail->From = 'myfromaddress@example.com';
$mail->FromName = 'My From Name';

or to set both name and address:

$mail->setFrom('myfromaddress@example.com', 'My From Name');
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 6
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now