Hi,

I wanted to try PHP's mail functionality, basically if I could send emails using GMAIL's SMTP server, in the same way I do it using Thunderbird (a mail program, similar to Outlook Express, but much better 😉.

As GMAIL requires a secure connection, it seems I can't use mail and have to use PHPMailer instead.

So I installed it and configured it, but when I try to send an email I get the following error:

"Mailer Error: The following From address failed: <my email address>"

The configuration is exactly as that of Thunderbird, but here it is so you can take a look at it:

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "smtp.gmail.com"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "<MY EMAIL ADDRESS>";  // SMTP username
$mail->Password = "<MY PASSWORD>"; // SMTP password
$mail->Port = 587;

$mail->From     = "<MY EMAIL ADDRESS>";
$mail->FromName = "<MY EMAIL ADDRESS>";
$mail->AddAddress("<RECIPIENT'S EMAIL ADDRESS>","User"); 

$mail->WordWrap = 50;                              // set word wrap
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the <b>HTML body</b>";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

Anyone came accross this problem before and was able to overcome it? Many thanks,

Javier

    Hi,

    you need to specify a valid from address in the code, like

    $mail->From     = "myaccount@test.com";
    $mail->FromName = "Givenname Lastname"; 
    

    You may have to specify your GMAIL address as from address (I never had a GMAIL account but there may be certain restrictions regarding the from address).

    Regards,
    Thomas

      But that is exactly what I'm doing, specifying my VALID gmail address, of course I didn't want to post it, so I was hoping people would interpret that where I had specified: <MY EMAIL ADDRESS> I am really putting my valid email address.

        Gmail requires TLS for SMTP authentication. AFAIK phpmailer doesn't support TLS.

        Try swiftmailer which supports TLS. I don't have any experience with swiftmailer but in the feature list they write about TLS support for Gmail servers.

          Thanks Tsinka. I have downloaded SwiftMailer and you are right, it says it supports TLS and can be setup for GMail... but I can't get it to work either.... might start a new thread about this issue. Thanks

            Write a Reply...