0

I wrote some code to send an email from my PHP script using PHPMailer. For some reason, the scripts isn't sending the messages.


Here Is My Code:

<?php
require_once("PHPMailer/class.phpmailer.php");
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "[email protected]";
$mail->Password = "PASSHERE";
$mail->SetFrom = "[email protected]";
$mail->AddAddress("[email protected]");
$mail->Subject = "Confirm Web Lock Registration!";
$mail->Body = "Please confirm your Web Lock Registration by clicking here!";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo "Message Sent!";
}
?>

This Is The Error Echoed:

SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.
9
  • Are you getting your error message echoed and if so what is it? Commented Oct 21, 2010 at 17:19
  • Could you give more information on the problem? Is it printing out the error message, or is it saying "Message Sent!" but you're still not receiving it? Commented Oct 21, 2010 at 17:20
  • @Zachary Brown: Never share your username and password publicly like this :) Commented Oct 21, 2010 at 17:21
  • 2
    You might want to remove or change the password in your question... Anyone viewing this can log in to your e-mail account right now. Commented Oct 21, 2010 at 17:23
  • meta.stackexchange.com/questions/43103/passwords-in-questions Commented Oct 21, 2010 at 17:26

5 Answers 5

3

Your error message might be caused by the firewall settings on your server. This error message is commonly caused by a firewall blocking outgoing connections on the port.

You also should make sure that you have the openssl extension enabled.

Original Answer that you fixed:

You are sending to [email protected] which is not the address you want.

You need to remove the second .com and change it to [email protected]

Sign up to request clarification or add additional context in comments.

2 Comments

Corrected it. Still the same problem.
I added some additional problems based on the error message you gave.
2

I'm using PHPMailer too, just tried your settings, and got the same error. Here are my settings witch work for me (I show with ->> things witch you don't have, or are different for me)

$mail->PHPMailer = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
->> $mail->SMTPSecure = "ssl";
->> $mail->Host = "smtp.gmail.com"; //not ssl://smtp.gmail.com
$mail->Port = 465; etc...

Everything else is the same, except i don't use word wrap, but i checked, it's not causing the problem.

Comments

1

You need to specify gmail username and password because that is the what you are using in smtp settings:

$mail->Username = "[email protected]";
$mail->Password = "yourgmailpassword";

1 Comment

The address is the username. The company uses Google Apps for email.
1

As a general tip, try turning on debugging:

$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                       // 1 = errors and messages
                       // 2 = messages only

From SO: Debugging PHP Mail() and/or PHPMailer

Comments

0

Just as a bit of advise you might also want to try using Zend_Mail, you can use this happily without having to go the whole MVC route and it is very informative

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.