Jump to content

Mail Error ... (Code Present)


pranshu82202

Recommended Posts

<?php  

require("class.phpmailer.php"); // path to the PHPMailer class

$mail = new PHPMailer();  

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourusername@gmail.com"; // SMTP username
$mail->Password = "yourpassword"; // SMTP password 

$mail->From     = "email address sender";
$mail->AddAddress("email address receiver");  

$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.';
}
?>

 

 

I am using this code to send mails via smtp...

 

But all the time i get the following error

 

SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.

 

Please tell me what shuld i do....

Link to comment
Share on other sites

Pran,

Did you edit the php.ini by putting that gmail server where it says smtp?

search for smtp, it should be under mail function, and the one says smtp = ". put your code below after that equal sign and your port under neath it.

ssl://smtp.gmail.com

465

And is there a reason why you have to use the phpmailer class? to me its much simpler to use the mail function. I've been sending out tons of email just using the mail function.

let me know if it works

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.