Hi, I'm using PHPMailer to send an activation link to the customer after registration.?

Now, when I sent the form, it says "SMTP Error: Could not authenticate. Error: SMTP Error: Could not authenticate."

In php.ini, I remove the semicolon in openssl then I've already restarted the wamp.

here's the code:


$code = sha1($text); //Encrypted

$mail = new PHPMailer ();

$mail -> From = "foo@gmail.com"; /////gmail account lang

$mail -> FromName = "OLEIA Pampanga"; //<<<< senders name

$mail -> AddAddress("validemail@yahoo.com"); //<<<< name reciever

$mail -> Subject = "Activate your account"; //<<<< subject

$mail -> Body = "<strong>Hello $ln, $fn</strong> <br /> Thank you for Registering to OLEIA.

Click this Activate link to activate your account <br /> <br />

<a href='http://localhost/Oleia/FrontEnd/activate.php?code=... //BODY

$mail -> IsHTML (true);


$mail->Host = 'ssl://smtp.gmail.com';

$mail->Port = 465;

$mail->SMTPAuth = true;

$mail->Username = 'foo@gmail.com'; //<<<< your gmail account

$mail->Password = 'foopassword'; //<<<< your gmail password

if(!$mail->Send()) {

echo 'Error: ' . $mail->ErrorInfo;


header("location: email_sent.php?email=$email");


1 Answer

  • 9 years ago
    Favorite Answer

    What host are you running this from? What host are you using as an SMTP server?

    I doubt that you're running it from "gmail.com", and I know that "gmail.com" won't allow external SMTP access. It may be necessary for your "From" address to be set to something on the same domain as your host machine. E.g., if you're using "www.myhost.com" as your email host, you'll need to set your "From" to "myaccount@myhost.com".

    You can set the "Reply-to" to a Gmail account, but not the "From" account.

    Recognize of course, that standard SMTP protocol doesn't care about who the "From" is, and you could set it to anything you like. But since you're using "openssl" for security and encryption, I suspect the rules are a little more strict.

    And don't try to relay thru gmail.com. I.e., you can't use them as an SMTP server. None of the web-email sites will allow that without following special rules (like sending them money). Don't forget, their sole income is in the advertising. If you could relay email thru their servers without going thru the web-interface, you can bypass all that advertising. That translates into Zero Dollars of Income, and they don't like that.

    The other thing to check is to see if the SMTP server requires authentication. Some of them do. Many will just allow you to send email with no account information (fewer and fewer, with all the Spam going around). Some will authenticate with what's called "Send after Fetch", since you always need to authenticate your account when FETCHING your email. So, you Fetch any email that's for you, after giving them your username and password, and if you Send within 5 or 10 minutes, it'll be good.

    But some servers require that you prove you have a valid account on their system for Fetch AND Send. I haven't done this with PHP, so I'll leave it as an exercise for the reader to check the manual for how to set the account information to use a server that requires authentication.

Still have questions? Get your answers by asking now.