Solved

PHPMailer

Posted on 2014-10-01
21
131 Views
Last Modified: 2014-10-08
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
Comment
Question by:APD_Toronto
  • 6
  • 6
  • 6
  • +1
21 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 167 total points
ID: 40355770
Did you set the correct port? (assuming your credentials are correct)
0
 

Author Comment

by:APD_Toronto
ID: 40355794
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
 
LVL 58

Expert Comment

by:Gary
ID: 40355807
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
 
LVL 25

Assisted Solution

by:Squinky
Squinky earned 167 total points
ID: 40355816
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
 

Author Comment

by:APD_Toronto
ID: 40355842
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
 
LVL 58

Expert Comment

by:Gary
ID: 40355847
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
 
LVL 25

Expert Comment

by:Squinky
ID: 40355851
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
 

Author Comment

by:APD_Toronto
ID: 40355872
I have tried all port numbers from above, the result is the same
0
 
LVL 58

Expert Comment

by:Gary
ID: 40355884
Firewall...?
0
 

Author Comment

by:APD_Toronto
ID: 40355890
I am emailing the hosting company now, will keep you posted.

If any other ideas in the mean time, please share.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 25

Expert Comment

by:Squinky
ID: 40356346
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
 
LVL 11

Assisted Solution

by:Murfur
Murfur earned 166 total points
ID: 40356698
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
 
LVL 25

Expert Comment

by:Squinky
ID: 40356714
Reposting what others have already said isn't very helpful.
0
 
LVL 11

Expert Comment

by:Murfur
ID: 40356798
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
 

Author Comment

by:APD_Toronto
ID: 40357372
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
 
LVL 25

Expert Comment

by:Squinky
ID: 40357447
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
 
LVL 58

Expert Comment

by:Gary
ID: 40357449
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
 

Author Comment

by:APD_Toronto
ID: 40357528
@Gary
>>3. Can be anything you like, doesn't matter
How?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40357555
It's just the From Name - could be your name, or anything.
0
 
LVL 25

Expert Comment

by:Squinky
ID: 40357564
$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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now