Here is my code:

require_once("PHPMailer/class.phpmailer.php");

$mail = new PHPMailer();

// set authentication
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Post = 587;
$mail->Username = "myemail@gmail";
$mail->Password = "myemailpassword";

// set From:
$mail->SetFrom("myemail@gmail.com", "First Last");

// set To:
$mail->AddAddress("adifferentemail@yahoo.com", "First Last");

// set Subject:
$mail->Subject = "Subject";

// set body
$mail->IsHTML(true);
$mail->Body = "<html>
    <body>
        <p>Body Text</p>
    </body>
</html>";
$mail->AltBody = "Sorry, your email client does not support HTML messages.";

// send mail
if (!$mail->Send())
    die($mail->ErrorInfo . "\n");

I've tried changing from TLS to SSL, I've tried it with and without authentication, with SMTPSend() instead of just Send(), but I always get the "The following From address failed: myemail@gmail.com : Called Mail() without being connected" error. Any ideas where this might be coming from? I'm really new at this, so it's probably something pretty obvious...

Recommended Answers

All 8 Replies

Hi,

You will have to let us know your server environment in which this script is running. For example.. wampp, xampp, or something else..

Looking at your codes above, it is utilizing the gmail account credentials. If you are running this script in production server environment, you will have to acknoledge the gmail confirmation request by logging in to your gmail account and click on the hard to miss red box on top the page. Make sure you are confirming the IP address on your server and NOT someone-elses.

I have no idea what my server environment is. Sorry... I'm using the CS50 Appliance from Harvard's CS50 course, if that helps (I'm not enrolled, so don't worry about cheating or anything). I edit PHP files, and I type in http://localhost to get to my developed site. Obviously, I've got Apache, PHP, and MySQL running.

$mail->Post = 587;

Should be "Port", not "Post"

i also coming this error but i have no eny solution
please help me

Message was not sent
PHPMailer Error: The following From address failed: dipali.sakle@gmail.com : Called Mail() without being connected
please give a solution of this error

Member Avatar for diafol

You need to show your code.

i am having the same problem as dipali sakle what can be the answer to solve it.. and does the phpmailer need specil setup in php.ini and sendmail.ini...Please do reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.