Hullo, I have been browsing through the internet on how best I can send an email from my website; and it seems like most were directing me to PHPMailer.
I added the php mailer folder onto my server, and now am attempting to test whether am email can really be sent. However, I keep getting this error message;

Message was not sent.Mailer error: The following From address failed: sample_mail@gmail.com : Called Mail() without being connected;

Here i sthe code I am using to send the email;

$mail = new PHPMailer();
$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.gmail.com"; // SMTP server
$mail->From     = "samle1@gmail.com";
$mail->Subject  = "First PHPMailer Message";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';

Can someone help me out on how to solve that error?

4 Years
Discussion Span
Last Post by Webville312

gmail does not use the standard smtp ports and from needs to be your existing email address. Then you need to use authentication and provide your password. There are several examples already in this forum.


@Pristaeas, So; what do I replace?? and with what??

I'm sorry, but it is the first time I am attempting to send an email from my website.


Thanx @Pritaeas, I followed the link you gave,and it gave me an idea, although did not solve my dilema.
However, I was able to get it to work. Here is the code I used [In case someone else faces the same challenge I faced];

    $email = $_POST['email'];
    $mail = new PHPMailer();
    $mail->Host = "localhost";
    $mail->From = "sender@domain.com";
    $mail->FromName  =  "My name";
    $mail->SMTPAuth = "true";
    $mail->Username = "mygmailemail@gmail.com";
    $mail->Password =  "mygmailpassword";
    $mail->Port  =  "25";

    $mail->Subject = "Test email";
    $mail->Body = "" This is a test email.;
    $mail->WordWrap = 50;

        echo 'Message was not sent.';
        echo 'Mailer error: ' . $mail->ErrorInfo;
        echo 'Email has been sent!!';
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.